Inserting PDF image to another PDF file

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

Post Reply
isaware
User
Posts: 39
Joined: Fri Sep 25, 2009 6:21 pm

Inserting PDF image to another PDF file

Post by isaware »

Hi,

I'm trying to grab an image from one PDF file to another PDF file.
PDF1 only has a small image and I want to stitch this image to PDF2.
I went through couple of APIs and found out that this is doable.
I'm grabbing the image using PXCp_ImageGetFromPage and PXCp_GetDocImageAsXCPage and acquired the pImage.
How can I put this image object on PDF2? I couldn't find any method that does it.
Also, it is better to just use the AddWatermark function (size/performance-wise)? The image from PDF1 will always going to be embedded on every page on PDF2.

Christina
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Inserting PDF image to another PDF file

Post by Lzcat - Tracker Supp »

Hi Christina.
There are several ways to do this:

1. If the source PDF page contains ONLY an image the best way is to use the PXCp_PlaceContents function to place this page on all needed pages in the destination document in one operation. Of course you may make several calls, but this will make the PDF file larger (you will get several copies of the image).

2. After getting XCPage you may create a new PDF file using pxclib, place the image (and maybe other required content) into it, save the file and then combine it with the destination pdf using PXCp_PlaceContents.

3. Use PXCp_SaveDocImageIntoFileW instead of PXCp_GetDocImageAsXCPage, and then use the PXCp_AddWatermark function to place the image on all required pages (better in one call, of course as explained above).

HTH.
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.
isaware
User
Posts: 39
Joined: Fri Sep 25, 2009 6:21 pm

Re: Inserting PDF image to another PDF file

Post by isaware »

Hi,

From your suggestion #1, can you tell me what kind of functions I need to use?
"place this page on all needed pages in the destination document in one operation"

Christina
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Inserting PDF image to another PDF file

Post by Lzcat - Tracker Supp »

Hi Christia.
This function is PXCp_PlaceContents :) For example you need place first page from source document over first ten pages of destination document. You may write

Code: Select all

for (int i = 0; i < 10; i++)
{
  PXCp_ContentPlaceInfo place_info;
  place_info.DestPage = i;
  place_info.SrcPage = 1;
  place_info.Alignment = CPA_HorCenter | CPA_VerCenter | CPA_Foreground;
  PXCp_PlaceContents(pDestDoc, pSourceDoc, 1, &place_info, 0);
}
or

Code: Select all

PXCp_ContentPlaceInfo place_info[10];
for (int i = 0; i < 10; i++)
{
  place_info.DestPage = i;
  place_info.SrcPage = 1;
  place_info.Alignment = CPA_HorCenter | CPA_VerCenter | CPA_Foreground;
}
PXCp_PlaceContents(pDestDoc, pSourceDoc, 10, &place_info, 0);
Both variants will work, and you will get expected results. With only one difference - in the first case you will get ten copies of a page and all of its resources (and get a larger file too!).
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.
isaware
User
Posts: 39
Joined: Fri Sep 25, 2009 6:21 pm

Re: Inserting PDF image to another PDF file

Post by isaware »

Hi,

I was able to grab the file and place it on another PDF successfully.

However, I'm getting a different problem now.
The source PDF (a.pdf) is an image that was cropped from another PDF(b.pdf) file.
If I open a.pdf file from my Adobe Reader, I see a small image that was cropped from b.pdf and this small area is what I want to paste.
However, when I attach this file (a.pdf) to my Destination file, I see the full content from b.pdf, not just the image that I cropped (a.pdf). It looks like even though a.pdf looks just like a small image, it contains the full content of it original file - b.pdf - hidden.

How can I just grab the visible part of the a.pdf file and place it on my destination file?


Christina
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Inserting PDF image to another PDF file

Post by Lzcat - Tracker Supp »

Hi Christina.
This is a bug, and it is already fixed. Fix will be avail with next build (4.0.0178).
However all what can be fixed in such case - just keep cropped content invisible, but not remove it from destination PDF.
Hope this will be enough.
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.
isaware
User
Posts: 39
Joined: Fri Sep 25, 2009 6:21 pm

Re: Inserting PDF image to another PDF file

Post by isaware »

Hi,

When does the next build release?

Christina
Last edited by isaware on Wed Feb 24, 2010 4:59 pm, edited 2 times in total.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Inserting PDF image to another PDF file

Post by John - Tracker Supp »

If all goes to plan - sometime next week.

Thanks for your patience.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
isaware
User
Posts: 39
Joined: Fri Sep 25, 2009 6:21 pm

Re: Inserting PDF image to another PDF file

Post by isaware »

Using PlaceContent method, can I place the PDF file at certain position rather than aligning ver/hoz?

Christina
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Inserting PDF image to another PDF file

Post by Lzcat - Tracker Supp »

Not at this moment, i'm afraid - there is not enough actual parameters to do this. However you may use a trick (regarding how this function works).

In a pdf the visible part of page is an intersection of the MediaBox and CropBox. For example if the MediaBox is [0 0 100 100] and the CropBox is [50 50 200 300] you will see only [50 50 100 100] rect. All content outside this rect will be invisible, so I'll call this intersection VisibleRect (it does not present in pdf in direct form). Normally PXCp_ContentPlaceInfo does the following:
1. Calculate the VisibleRect for source and destination pages.
2. Convert the souce page to an object which can be placed on the page.
3. Using both VisibleRect from step 1 and flags parameter calculate matrix for this object (the matrix contains the position in absolute coordinates and scale coefficients) and places the object from step 2 on the page.

So it is possible to use a trick adjusting the VisibleBox at the time when PXCp_ContentPlaceInfo is called.

For example you have page and need to place this page into the rect [100 150 200 200]. We should:
1. store the page MediaBox (and CropBox if it set).
2. Set the MediaBox to [100 150 200 200] (and adjust the CropBox if it is set and not fully covering the required rect).
3. Call the PXCp_ContentPlaceInfo function to place the content. The VisibleRect adjusted content will be placed where you require.
4. Restore the MediaBox (and CropBox if changed).

Now you will get the placed content where you require :wink:
To deal with page Boxes you will need the PXCp_PageGetBox and PXCp_PageSetBox functions. And please note the PDF coordinate system is not as you might expect, the([0 0] position is in the left-bottom corner, Y axis direction is up) and boxes notation ().
HTH.
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.
Post Reply