Copying Images

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

Dean64
User
Posts: 2
Joined: Wed Oct 01, 2008 2:20 pm

Copying Images

Post by Dean64 »

What is the best way to copy an image from an existing PDF file to a new PDF file such that it retains the original dimensions? I have tried copying to file and back in again (which works) but I cannot work out how to make the new image the same size as the old image. I cannot find a direct method to copy from one pdf to another. The interface is quite confusing as some methods deal with image ids and other deal with image structures.
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Copying Images

Post by Lzcat - Tracker Supp »

There is no way to copy part of content from one PDF to another in one step - you must extract image and then place it to destination PDF.
PDF files use specific mechanism to place image on page:
1. All images are treated as they has 1 to 1 point dimentions, regardless their original size in pixels.
2. To display image at specific position transformation matrix is used. It set position and dimentions of image on page, as well as rotation, flipping and so on. Detailed information about PDF matrices can be found in help to pxclib40, section Coordinate System, as well as in PDF Refernece, section 4.2 Coordinate Systems. Note that lower-left corner of image has (0, 0) coordinate, and upper-right corner - (1, 1). To calculate real coordinates of image corners on pdf page you must transfrom corresponding point using specified matrix. For example for upper-left corner (0, 1) coordinates will be (0 * a + 1 * c + e, 0 * b + 1 * d + f), where a, b, c, d, e, f are coefficients from corresponding matrix.
3. Same image may be shared between many pages and placed many times on same page (to reduce file size).
Because of this xcpro40 provide mechanism to enum all images in pdf file or enum images on specific page. Also, when getting information about image on specific page using PXCp_ImageGetFromPage you will get imageID (image identifier, used to extract image or save it to file) and PXC_Matrix, which specify how image was placed on page (see note 2 above). To place image on another pdf you should extract it (better use PXCp_GetDocImageAsXCPage if you are using pxclib40 to create new pdf, or save it to file otherwise), and than place it where you need.
Also, when extracting images from pdf xcpro40 retain their original dimentions in pixels, which may differ from visual dimentions on page.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Dean64
User
Posts: 2
Joined: Wed Oct 01, 2008 2:20 pm

Re: Copying Images

Post by Dean64 »

Many thanks Victor. I had pretty much got it all working but I had just missed the significance of the matrix in defining the dimensions of the original image. With that it now works perfectly.