RubyPDF Blog English,PDF right way to get DPI 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 or is jbig2.exe responible for this?

after check the last version, I notice it uses a default DPI(600). Images has different DPI, so if you want to use, 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.


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

Hi Steven,
thank you very much for your quick response, and the new
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 :-)


6 thoughts on “ 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 “”, line 171, in
    main(sym, pages)
    File “./”, 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:

    I think we need a sort of *if…then..else* condition where, if the *fake* dpi appears settled to zero, then 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.