How do I copy an image from an existing PDF file to a new PDF file and retain the original dimensions?
Images must be extracted and inserted (as opposed to copied and pasted) in order to move them between PDF files. This is because PDF files handle images in a unique manner. Notably:
The lower-left corner of images has the coorindates (0,0) and upper-right corner has (1,1). A specified matrix must be used in order to transform corresponding corners and calculate the real coordinates of image corners.
For example, the upper-left corner (0,1) coordinates will be (0 * a + 1 * c + e, 0 * b + 1 * d + f), where a, b, c, d, e and f are coefficients from the corresponding matrix.
Images are shared (as opposed to duplicated) when they are featured on many pages/placed multiple times on the same page. This is done in order to reduce the file size. Therefore, xcpro40 provides a simple mechanism that enumerates all images in a PDF file/on a specific page. (Please note that xcpro40 retains the original dimensions of images in pixels, and these may differ from the visual dimensions when they are displayed on the page).
Additionally, when PXCp_ImageGetFromPage is used to return information about images on specific pages, an imageID and PXC_Matrix will be present. The imageID is used to extract/save images to file and the PXC_Matrix specifies how images were placed on the page.These values should be used to extract/place images in PDF files.
N.b. If pxclib40 is being used to create/save PDF files then it is best to use PXCp_GetDocImageAsXCPage to extract images.
You can contact us by phone, email or our social media accounts — we are here to assist you.