Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Merge two PDFs and merge outlines (bookmarks) |
Post Reply |
Author | |
Rowan
Moderator Group Joined: 10 Jan 09 Status: Offline Points: 398 |
Post Options
Thanks(0)
Posted: 10 May 11 at 8:27AM |
Here is some Delphi sample code that helps you to merge two PDF files and also merge their respective outlines / bookmarks.
var oldpagecount: Integer; function GetOutlineIndex(QPL: TQuickPDF; OutlineID: Integer): Integer; var i: Integer; begin Result := 0; with QPL do begin for i := 1 to OutlineCount do {$IF LibVerNum >= 7.23} if CompareOutlines(GetOutlineID(i), OutlineID) = 1 then begin Result := i; Exit; end; {$IFEND} end; end; procedure MergeOutlines(QPL: TQuickPDF; DocumentID: Integer; PageOldCount: Integer); type TOutline = record Title: AnsiString; Page: Integer; DestPage, DestType: Integer; Left, Top, Right, Bottom, Zoom: Double; ColorRed, ColorGreen, ColorBlue: Double; StyleBold, StyleItalic: Integer; JavaScript, OpenFile, WebLink: String; Parent: Integer; end; var i: Integer; seldoc: Integer; outlineoldcount: Integer; outlineindex, outlineid: Integer; outlines: array of TOutline; begin with QPL do begin seldoc := SelectedDocument; outlineoldcount := OutlineCount; SelectDocument(DocumentID); for i := 1 to OutlineCount do begin SetLength(outlines, i+1); outlineid := GetOutlineID(i); outlines.Title := OutlineTitle(outlineid); outlines.Page := GetOutlinePage(outlineid) + PageOldCount; outlines.DestPage := GetDestPage(GetOutlineDest(outlineid)) + PageOldCount; outlines.DestType := GetDestType(GetOutlineDest(outlineid)); outlines.Left := GetDestValue(GetOutlineDest(outlineid), 1); outlines.Top := GetDestValue(GetOutlineDest(outlineid), 2); outlines.Right := GetDestValue(GetOutlineDest(outlineid), 3); outlines.Bottom := GetDestValue(GetOutlineDest(outlineid), 4); outlines.Zoom := GetDestValue(GetOutlineDest(outlineid), 5); outlines.ColorRed := GetOutlineColor(outlineid, 0); outlines.ColorGreen := GetOutlineColor(outlineid, 1); outlines.ColorBlue := GetOutlineColor(outlineid, 2); outlines.StyleBold := (GetOutlineStyle(outlineid) and 2) shr 1; outlines.StyleItalic := GetOutlineStyle(outlineid) and 1; outlines.JavaScript := GetOutlineJavaScript(outlineid); outlines.OpenFile := GetOutlineOpenFile(outlineid); outlines.WebLink := GetOutlineWebLink(outlineid); // searching for parent outline outlineindex := GetOutlineIndex(QPL, GetParentOutline(outlineid)); if outlineindex <> 0 then outlines.Parent := outlineindex + outlineoldcount; end; SelectDocument(seldoc); for i := 1 to Length(outlines) - 1 do begin outlineid := NewOutline(GetOutlineID(outlines.Parent), outlines.Title, outlines.Page, 0); SetOutlineDestinationFull(outlineid, outlines.DestPage, Round(outlines.Zoom), outlines.DestType, outlines.Left, outlines.Top, outlines.Right, outlines.Bottom); SetOutlineColor(outlineid, outlines.ColorRed, outlines.ColorGreen, outlines.ColorBlue); SetOutlineStyle(outlineid, outlines.StyleItalic, outlines.StyleBold); if outlines.JavaScript <> '' then SetOutlineJavaScript(outlineid, outlines.JavaScript); if outlines.OpenFile <> '' then SetOutlineOpenFile(outlineid, outlines.OpenFile); if outlines.WebLink <> '' then SetOutlineWebLink(outlineid, outlines.WebLink); end; end; end; begin // create and unlock PDFLibrary here and load some PDF to merge to... with PDFLibrary do begin with TOpenDialog.Create(nil) do begin if not Execute then Exit; LoadFromFile(FileName); // to merge LoadFromFile(FileName); // to copy outlines from Free; end; SelectDocument(GetDocumentID(DocumentCount - 2)); oldpagecount := PageCount; MergeDocument(GetDocumentID(DocumentCount - 1)); SelectDocument(GetDocumentID(DocumentCount - 1)); MergeOutlines(PDFLibrary, GetDocumentID(DocumentCount), oldpagecount); end; // here output PDF can be saved or rendered... end; |
|
isyscorp
Beginner Joined: 30 Aug 12 Location: Philippines Status: Offline Points: 19 |
Post Options
Thanks(0)
|
Hi, thank you for this. Been trying to make it to work but no luck. Kindly help me please make this to work, all i need is to combine 2 or more PDF files into ONE PDF File.
Thanks,
Vid |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Vid!
You should post your code here and we'll see if we can help. BTW: Please post problems at "i need help..." ;-) Cheers and welcome here, Ingo |
|
isyscorp
Beginner Joined: 30 Aug 12 Location: Philippines Status: Offline Points: 19 |
Post Options
Thanks(0)
|
Hi Ingo, i am trying Rowan's code, but i receive this error message:
"Record, object or class rwquired" at line: outlines.Title := OutlineTitle(outlineid); Thanks for your help, Vid
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store