There is not a single “imposition” function in Debenu Quick PDF Library but it’s easy to use the CapturePage and DrawCapturedPage functions to do the imposition. There is some sample code below that demonstrates how to take a few different PDFs, merge them together, and then impose each page onto one page in a new document. The sample is written in Delphi, but should be easy enough to understand for users of other languages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
unit ImpoDemo; interface uses Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, ComCtrls, StdCtrls, DebenuPDFLibrary1113, ExtCtrls; type TfrmDemo = class(TForm) 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 PDFLib: TDebenuPDFLibrary1113; Counter: integer; posx, posy: double; // left, bottom dimx, dimy: double; // sheet size w, h: double; i, j: integer; capt:array of ObjRec; begin PDFLib := TDebenuPDFLibrary1113.Create; if PDFLib.UnlockKey('...add_license_key_here...') = 1 then begin // Quelldateien laden PDFLib.AddToFileList('List', 'tiger_emf.pdf'); PDFLib.AddToFileList('List', 'debenu final tm.pdf'); // workfile PDFLib.MergeFileList('List', '_temp.PDF'); PDFLib.LoadFromFile('_temp.PDF'); PDFLib.SetMeasurementUnits(1); // millimeters DeleteFile('_temp.PDF'); Counter := PDFLib.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 := PDFLib.GetPageBox(1,2); capt[i].h := PDFLib.GetPageBox(1,3); capt[i].id := PDFLib.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 (PDFLib.PageCount=1) then PDFLib.NewPage; // never empty end; // imposition PDFLib.SelectPage(1); dimx := 600; dimy := 400; PDFLib.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 PDFLib.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 PDFLib.DeletePages(PDFLib.PageCount(), 1); // Save our work PDFLib.SaveToFile('debenu_quick_pdf_library_imposition.pdf'); end else ShowMessage('Sorry, but the license key you provided could not be validated.'); end; end. |
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, DebenuPDFLibrary1113, ExtCtrls;
type
TfrmDemo = class(TForm)
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
PDFLib: TDebenuPDFLibrary1113;
Counter: integer;
posx, posy: double; // left, bottom
dimx, dimy: double; // sheet size
w, h: double;
i, j: integer;
capt:array of ObjRec;
begin
PDFLib := TDebenuPDFLibrary1113.Create;
if PDFLib.UnlockKey('...add_license_key_here...') = 1
then begin
// Quelldateien laden
PDFLib.AddToFileList('List', 'tiger_emf.pdf');
PDFLib.AddToFileList('List', 'debenu final tm.pdf');
// workfile
PDFLib.MergeFileList('List', '_temp.PDF');
PDFLib.LoadFromFile('_temp.PDF');
PDFLib.SetMeasurementUnits(1); // millimeters
DeleteFile('_temp.PDF');
Counter := PDFLib.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 := PDFLib.GetPageBox(1,2);
capt[i].h := PDFLib.GetPageBox(1,3);
capt[i].id := PDFLib.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 (PDFLib.PageCount=1) then PDFLib.NewPage; // never empty
end;
// imposition
PDFLib.SelectPage(1);
dimx := 600;
dimy := 400;
PDFLib.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
PDFLib.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
PDFLib.DeletePages(PDFLib.PageCount(), 1);
// Save our work
PDFLib.SaveToFile('debenu_quick_pdf_library_imposition.pdf');
end
else ShowMessage('Sorry, but the license key you provided could not be validated.');
end;
end.