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

Multiple drawing of many small PDFs in a new one (imposition)

Question

How do I impose multiple pages from a variety of small PDFs into one big page in a new document?

Answer

Some sample code that demonstrates how to take a few different PDFs, merge them together, and then impose each page onto one page in a new document can be found below. The sample is written in Delphi, but should be easy enough to understand for users of other languages.

unit ImpoDemo;
interface

uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, QuickPDF0717, ExtCtrls;

type
TfrmDemo = class(TForm)
edtLicenseKey: TEdit;
PanControl: TPanel;
BtnCreatePage: TButton;
StaticText2: TStaticText;
ImpositionScrollBox: TScrollBox;
Memo1: TMemo;
Label1: TLabel;
procedure BtnCreatePageClick(Sender: TObject);
private
public
{ Public declarations }
end;

var
frmDemo: TfrmDemo;

implementation
{$R *.dfm}

procedure TfrmDemo.BtnCreatePageClick(Sender: TObject);
type
ObjRec=record // description of imposition-object
id: integer; // page-id
w, h: double; // size
end;
var
QP: TQuickPDF;
Counter: integer;
posx, posy: double; // left, bottom
dimx, dimy: double; // sheet size
w, h: double;
i, j: integer;
capt:array of ObjRec;
begin
QP := TQuickPDF.Create;
if QP.UnlockKey(edtLicenseKey.Text) = 1
then begin
// Quelldateien laden
QP.AddToFileList('List', 'tiger_emf.pdf');
QP.AddToFileList('List', 'debenu final tm.pdf');
// workfile
QP.MergeFileList('List', '_temp.PDF');
QP.LoadFromFile('_temp.PDF');
QP.SetMeasurementUnits(1); // millimeters

DeleteFile('_temp.PDF');
Counter := QP.PageCount; // PageCount is number of objects
SetLength(capt, Counter); // make the array
for i:=0 to Counter-1
do begin // get the sizes from Mediabox
StaticText2.Caption := IntToStr(i);
capt[i].w := QP.GetPageBox(1,2);
capt[i].h := QP.GetPageBox(1,3);
capt[i].id := QP.CapturePage(1); // from the top
// to see the values
Memo1.Lines.Add(Format('%d: %fx%f (%d)',[i, capt[i].w, capt[i].h, capt[i].id]));
if (QP.PageCount=1) then QP.NewPage; // never empty
end;
// imposition
QP.SelectPage(1);
dimx := 600;
dimy := 400;
QP.SetPageDimensions(dimx, dimy); // size for output

Memo1.Lines.Add('');
posx := 5; // left border 5mm
posy := 5;
for i:=0 to Length(capt)-1 // every object as often as possible in a line
do begin
StaticText2.Caption := IntToStr(i+1);
w := capt[i].w;
h := capt[i].h;
j := 1;
while (posx + w < dimx-5)
do begin
QP.DrawCapturedPage(capt[i].id, posx, posy+h, w, h);
Memo1.Lines.Add(Format('object %d as %fx%f',[i+1, w, h]));
posx := posx + w+10; // distance between objects
w := w*j/(j+1); // more and more less
h := h*j/(j+1);
inc(j);
end;
posy := posy + capt[i].h+10;
posx := 5; // left border 5mm
end;

// Delete the extra page that was created when the original pages were captured
QP.DeletePages(QP.PageCount(), 1);
// Save our work
QP.SaveToFile('QP imposition.pdf');
end
else ShowMessage('Sorry, but the license key you provided could not be validated.');
end;

end.

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