How do I
copy an image from an existing PDF file to a new PDF file and retain the original dimensions?
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:
Images are treated with 1 to 1 point dimensions, regardless of their original size in pixels.
Transformation matrices are used in order to display images at specific locations. This determines the position/dimension of images on pages, as well as rotation/flipping values and other similar settings. Further information about PDF matrices is available in the PDF-ToolsV4SDK.pdf help file of the pxclib40, as well as in section 4.2 of Adobe's PDF Reference, Sixth Edition, which is available here.
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, xcpro40provides 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.