I work for a large book manufacturer, and my current project is to write some vb code for some basic preflight procedures on pdf’s using PDFTron. Some of these procedures include - finding page trim size, find any missing fonts, find any text that uses a missing font and highlight it, adding trim lines, find all used colors, search for specific text, find and highlight any element that is too close to the page edge (page bleed warning), and find/highlight any low-res image. (some are for customer reference/use, and some are for prepress operator use) I’m stuck on finding the resolution on rotated images within the pdf as I’m getting inaccurate results. I’ve tried finding the average scaling x,y for the image, and then calculating dpi (as suggested on this forum) with inaccurate results. I’ve also tried removing the rotation angle from the image and then calculating the dpi without writing the modified image with no success. The CTM is a little bit tricky to understand, so I’ve spent a lot of time reading through this forum, reading the PDF Reference, and writing and re-writing vb code. Any guidance would be greatly appreciated.
So matching the SO post and PDFNet SDK you have
Xx : m_a
Xy : m_b
Yx : m_c
Yy : m_d
We don’t need to consider m_h or m_v because that is just displacement.
That will give you your scales, and then taking PDF at 72 DPI, and getting the Image height and width, I believe you can get your effective resolution.
I did not get a chance to test but I think the following is what will work.
Thanks Ryan. I’m now testing with the following vb code which seems to work on all images except for ones with shearing (dpi values are off). Any direction on this?
…
'determine effective resolution of image
Dim imagewidth As Double = element.GetImageWidth()
Dim imageheight As Double = element.GetImageHeight()
Dim mtx As Matrix2D = element.GetCTM()
Dim scalex As Double = Math.Sqrt((mtx.m_a * mtx.m_a) + (mtx.m_b * mtx.m_b))
Dim scaley As Double = Math.Sqrt((mtx.m_c * mtx.m_c) + (mtx.m_d * mtx.m_d))
Dim xRes As Double = Math.Abs(imagewidth * 72 / scalex)
Dim yRes As Double = Math.Abs(imageheight * 72 / scaley)
'determine rotation angle of image
Dim radians As Double = Math.Atan2(mtx.m_b, mtx.m_a)
Dim rot_angle As Double = Int(radians * (180 / Math.PI))