Menu

#5 Page resolution

open
nobody
None
5
2005-11-02
2005-11-02
d4rk
No

First of all, the library is excellent.

Would it be possible to add an option to set page
resolution in addition to the page size? For example,
if I am inserting a high resolution image (say from a
scanner that scanned at 300dpi),then the image size
would be pretty high, but I would still like the image
to be displayed in a 8.5x11in document, so if the page
resolution is increased to 300dpi, then the image will
display correctly.

Thanks and again, keep up the excellent work!

Cheers!

Discussion

  • LeslieM

    LeslieM - 2006-01-17

    Logged In: YES
    user_id=1429115

    Hi CodeLogic,

    I think that pages are fixed at 72 DPI as per the PDF
    standard (I could be wrong though).

    Now I had the same problem and with painful trial and error
    realised that pdf_contents_concat() can actually rescale
    the image for you - I still have not worked out Parameters
    3 & 4 but suspect they are to do with image rotation.

    If you know the DPI then basically you can calculate a
    scale factor and do the following

    pdf_contents_concat(hImage, Width/ScaleFactor, 0, 0,
    Height/ScaleFactor, X, Y);

    I made a minor change to my copy of the static library to
    allow me to get the PixelsPerMetre() of a PNG image as I
    never know ahead of time the DPI. I have not made the
    equivalent in jpeg as I don't need it but taking a look it
    seems pretty simple to do.

    Leslie.

     
  • d4rk

    d4rk - 2006-01-17

    Logged In: YES
    user_id=1238652

    Hi Leslie,

    I think you are right, the PDF spec fixes the resolution at
    72dpi (I discovered this later). I will check out
    'pdf_contents_concat', thanks for the tip!

    Cheers,
    CodeLogic.

     
  • Ade

    Ade - 2006-11-06

    Logged In: YES
    user_id=1298231

    Hi,

    You can already achieve image resolution on a page at higher than 72 DPI by scaling the image when you draw it - note that this
    does not re-compress the image or change the image in any way:

    HPDF_REAL ScaleDPI(HPDF_REAL size) { return size * (72.0F / requiredDPI); }

    HPDF_Page_DrawImage(page, image, x, y, ScaleDPI(HPDF_Image_GetWidth(image)), ScaleDPI(HPDF_Image_GetHeight(image)));

    where requiredDPI can be 300 or whatever you require for your image.

    This is more flexible as you can then mix and match image DPIs on the same page (eg a scanned image at 200 DPI, a screen capture at
    96 DPI and an photo at 600 DPI)

    Best regards,
    Adrian Nelson

     

Log in to post a comment.