How to determine dpi of a image inside PDF?

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

How to determine dpi of a image inside PDF?

Post by Dorwol »

Hi,

I want to use "PXCp_SaveDocImageIntoFileW" for saving an image from a PDF file after usage og "PXCp_ImageGetFromPage".

PXCp_SaveImageOptions needs the correct DPI value of this image.

How do I get this important value?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to determine dpi of a image inside PDF?

Post by Tracker Supp-Stefan »

Hello Dorwol,

PXCp_ImageGetFromPage and
PXCp_ImageGetFromPageEx
Will return the
pMatrix :
[out] Matrix which defines element transformation parameters. It is a combination of all
transformations (position, scaling, rotation and so on) that have been used to produce the resulting
output. The e and f parameters contain the starting location of the text element on the page, and
are based on the mediabox coordinates.
See PDF the Adobe PDF Reference 1.6, section 4.2.2 Common Transformations for more
information.

And using this you can calculate the image's "physical" dimensions on the original page, and when you have the pixel count and the original dimensions - calculate the original DPI at which it was displayed.

Regards,
Stefan
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: How to determine dpi of a image inside PDF?

Post by Dorwol »

Tracker Supp-Stefan wrote:PXCp_ImageGetFromPage and
PXCp_ImageGetFromPageEx
Will return the
pMatrix :
Already tried yesterday, but without success.

I was using your sample-code (in folder "PDF-XChange Pro SDK\Examples\SDKExamples\VBExamples\PXCPro_Demo")
And insert this MsgBox inside the code:

Code: Select all

                res = PXCp_ImageGetFromPage(pdf, i, j, ImageHandle, matrix)
                If optSave1.Value = True Then
                
                   MsgBox matrix.e & " / " & matrix.f
                
                    Dim pSaveOpts As PXCp_SaveImageOptions
                    pSaveOpts.fmtID = nSaveFmt(sel)
                    pSaveOpts.imgType = nSaveFmtBpp(sel)
But the Messagebox shows only "0 / 0".
Tested with many PDF-Files. Always zero value!
Try it please!

Any idea?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to determine dpi of a image inside PDF?

Post by Ivan - Tracker Software »

.e and .f members of the matrix specify the position of the image on a page.

To get a DPI of the image on the page, you have to know the dimensions of the image in pixels and also the size of the image on the page (in inches):

dpix = width_in_pixels / width_in_inch;
dpiy = height_in_pixels / height_in_inch;

simply put, when an image is placed without rotation, its size of the page can be taken from matrix:

widht_in_inch =matrix.a / 72.0;
height_in_inch = matrix.d / 72.0;

(in general terms you will have to transform vectors (0, 1) and (1, 0) by that matrix and get their length after transformation)

Unfortunately, to get image dimensions in pixels you have to use PXCp_GetDocImageAsXCPage and work with the image our Image-XChange SDK, or save the file to disk, and use another 3rdparty API to get the image size.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Post Reply