Created
June 2, 2015 10:21
-
-
Save rowanhanna/0c448afafeafcdb31ebd to your computer and use it in GitHub Desktop.
Delphi code snippet for overlaying one page from a PDF onto another page in a different PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure TForm2.btnOverlayClick(Sender: TObject); | |
var | |
FileA: Integer; | |
FileB: Integer; | |
CapturedPageID: Integer; | |
PageHeight: Double; | |
PageWidth: Double; | |
Path: AnsiString; | |
begin | |
DPL := TDebenuPDFLibrary1114.Create; | |
try | |
UnlockResult := DPL.UnlockKey('...'); // Insert trial or paid license key here | |
if UnlockResult = 1 then | |
begin | |
// You can only use the DrawCapturedPage function if the captured page is in the same | |
// document, so first we'll need to merge the two pages that we wish to overlay together | |
// into one document. | |
if dlgOpen.Execute then | |
begin | |
DPL.LoadFromFile(dlgOpen.FileName, ''); | |
FileA := DPL.SelectedDocument(); | |
end; | |
if dlgOpen.Execute then | |
begin | |
DPL.LoadFromFile(dlgOpen.FileName, ''); | |
FileB := DPL.SelectedDocument(); | |
end; | |
// After merging FileB is automatically deleted, leaving only FileB which is now a combination of FileA and FileB | |
DPL.SelectDocument(FileA); | |
DPL.MergeDocument(FileB); | |
// Capture the second page in the merged document | |
CapturedPageID := DPL.CapturePage(2); | |
// Now select the first page and retrieve its height and width | |
DPL.SelectDocument(FileA); | |
DPL.SelectPage(1); | |
PageHeight := DPL.PageHeight(); | |
PageWidth := DPL.PageWidth(); | |
// Draw the captured page onto the currently selected page | |
DPL.DrawCapturedPage(CapturedPageID, 0, PageHeight, PageWidth, PageHeight); | |
// Save the stitched file to disk | |
if dlgSave.Execute then | |
begin | |
Path := dlgSave.FileName; | |
end; | |
DPL.SaveToFile(Path); | |
end; | |
finally | |
DPL.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment