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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - Merge two PDFs and merge outlines (bookmarks)
  FAQ FAQ  Forum Search   Register Register  Login Login

Merge two PDFs and merge outlines (bookmarks)

 Post Reply Post Reply
Author
Message
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Topic: Merge two PDFs and merge outlines (bookmarks)
    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;
Back to Top
isyscorp View Drop Down
Beginner
Beginner
Avatar

Joined: 30 Aug 12
Location: Philippines
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote isyscorp Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 12 at 1:42AM
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
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 12 at 9:03PM
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

Back to Top
isyscorp View Drop Down
Beginner
Beginner
Avatar

Joined: 30 Aug 12
Location: Philippines
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote isyscorp Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 12 at 12:43AM
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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store