Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Capture a page from a document and draw it onto another page

Question

I'm using the 30 day trial of Quick PDF Library with Delphi 7. My only one problem: I need to import a page from an existing PDF into a new PDF that I'm creating.

  1. How may I copy the page from the first document as a real page, not as an image?

  2. How do I then draw this page onto the new blank page in my new document? I know nothing about the existing structure of the PDF. It may content vectors or some other element and therefore I don't want the copied page to be an image.

Answer

A possible solution is to open the existing one-page-document and to set a new page as page 1 in this document. So we may capture the page 2 (the existing page we want to put anywhere) and use the DrawCapturedPage-functionality.

QP := TQuickPDF.Create;
if QP.UnlockKey('use here your key') = 1
then begin
QP.LoadFromFile(PDF1); // the old PDF we want to get as copy

// be carefull, now is the right moment to ask for width and height 
// and all you need to know

W := QP.PageWidth;
H := QP.PageHeight;

// now we build the target for PDF1

QP.NewPage;// new (empty) page is appended
QP.MovePage(1);// becomes page 1

// now we take the old page 1 for further use

PageID := QP.CapturePageEx(2, 1); // take page 2 in size of its Mediabox

// prepare the target as you need

QP.SetPageDimensions(Width, Height);
QP.SetMeasurementUnits(1); // unit mm
QP.SetOrigin(0); // 0 Bottomleft
QP.DrawBox(0, 0, BlockWidth, BlockHeight, 1); // Background filled

QP.SaveState;
QP.DrawRotatedCapturedPage(PageID, 0, BlockHeight-H, W, H, 0);
QP.LoadState;

QP.SaveToFile('the_wanted.pdf');

Because we no nothing about the content it is a good idea to use savestate before drawing the captured page and loadstate after doing this. So we have no susprises depending from the existing page.

If there is more than only one page to use as source, we may go over MergeFile-functionality, because we need all sources to be in our PDF.

Have fun, Werner


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum