RubyPDF Blog English,PDF Jbig2.pdf.py.patch-The right way to get DPI

Jbig2.pdf.py.patch-The right way to get DPI

Yesterday, I got a comment on Jbig2

Hi Steven,
thanks for the port to windows. It works very good, produces small pdf-file sizes. Only one strange thing happens. The generate pdf files have a huge page-size. For example if I process A4-size pages (29.7×20.9cm) @400dpi tiff or png the pdf file size is 164.9×116.6 cm.
Is it possible to fix this by the python pdf.py or is jbig2.exe responible for this?
Thanks
Armin

after check the last version pdf.py, I notice it uses a default DPI(600). Images has different DPI, so if you want to use pdf.py, you need always modify it, it is not a good solution.

Then I check the source code of jbig, and found in jbig2_page_info structure ,

struct jbig2_page_info {
  u32 width;
  u32 height;
  u32 xres;
  u32 yres; ...

we can get xres and yres, so we can directly use xres and yres to generated proper page size.

and here is the patch file

btw, you can also download the last version jbig2 from here.

P.S.

Armin became the first user, and here is his response,

Hi Steven,
thank you very much for your quick response, and the new pdf.py
which works perfect. (I checked it with my 400dpi page scans.
the pdf page size is now of the same size as the scans)

Thank you so much,
Greetings from rainy Germany :-)

Armin

6 thoughts on “Jbig2.pdf.py.patch-The right way to get DPI”

  1. We have a serious problem

    thanks for patch, it works very fine when image has a dpi rightly settled, however, if we edit images with a program that strip the original dpi info (settling to zero) we have this error:

    Traceback (most recent call last):
    File “pdf.py”, line 171, in
    main(sym, pages)
    File “./patched-pdf.py”, line 129, in main
    contents = Obj({}, ‘q %f 0 0 %f 0 0 cm /Im1 Do Q’ % (float(width * 72) / xres, float(height * 72) / yres))
    ZeroDivisionError: float division

    I uploaded a test image here: http://goo.gl/eVdOi

    I think we need a sort of *if…then..else* condition where, if the *fake* dpi appears settled to zero, then pdf.py will produce pdf output without calculating mediabox via division between dpi and pixel size

  2. It is a bug of my code, If images have no a DPI, we should set a default DPI, for example by default is 72, and we can set it as parameter.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.