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?
How to determine dpi of a image inside PDF?
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: How to determine dpi of a image inside PDF?
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
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
Re: How to determine dpi of a image inside PDF?
Already tried yesterday, but without success.Tracker Supp-Stefan wrote:PXCp_ImageGetFromPage and
PXCp_ImageGetFromPageEx
Will return the
pMatrix :
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)
Tested with many PDF-Files. Always zero value!
Try it please!
Any idea?
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
Re: How to determine dpi of a image inside PDF?
.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.
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.
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.