Maintaining bookmark structure while concatenate multiple pdfs

Hi,

I'm new to Aspose.pdf. I'm trying to combine multiple pdfs into one pdf, and maintain each pdf's bookmark structure in the merged file. I want to create one top level bookmark for each pdf file, then keep the same bookmark structure in the pdf under the newly created bookmark. basically, the same functionality as the Acrobat's "Combine supported files in Acrobat" context menu command.

I've tried using the "pdfDocument1.Pages.Add(pdfDocument2.Pages)" to add all pages into the new document, and loop through each pdf's OutlineItemCollection to create new bookmarks.

Is this the way to go, or is there an easier way to achieve this?

I'd appreciate some code sample to traverse the OutlineItemCollection as I can't figure out how to calculate the new "destination" from the current outlineItem's destination (no exposed properties such as a "goto page #").

Thanks,

Jian

jsong:
I’m new to Aspose.pdf. I’m trying to combine multiple pdfs into one pdf, and maintain each pdf’s bookmark structure in the merged file. I want to create one top level bookmark for each pdf file, then keep the same bookmark structure in the pdf under the newly created bookmark. basically, the same functionality as the Acrobat’s “Combine supported files in Acrobat” context menu command.

I’ve tried using the “pdfDocument1.Pages.Add(pdfDocument2.Pages)” to add all pages into the new document, and loop through each pdf’s OutlineItemCollection to create new bookmarks.

Is this the way to go, or is there an easier way to achieve this?

I’d appreciate some code sample to traverse the OutlineItemCollection as I can’t figure out how to calculate the new “destination” from the current outlineItem’s destination (no exposed properties such as a “goto page #”).

Hi Jian,

Thanks for your interest in our products and sorry for replying you late.

Please share that the individual PDF files which you are planning to concatenate, does they also include BookMarks and you want these Bookmarks to be properly appearing in final Merged PDF document ?

Or you need to combine some individual PDF files and create Bookmarks pointing to individual pages inside the concatenated document.

Please share the details so we may answer accordingly. We are sorry for your inconvenience.

Hi, Nayyer,

Thanks for the reply.

Yes, I want to concatenate multiple pdfs into one. I already figured out how to create new bookmarks for each file added to the merged file.

Now, each individual pdf contains bookmarks and I want to transfer them to the merged file at the proper place (under the new bookmark I just created for this file).

Sorry I cannot share my pdf files as they contain company infomation, but any pdf files with bookmarks could be used for testing. I'm just looking for some sample code to work with the bookmarks.

Thanks,

Jian

Hi, Nayyer,

I figured out how to transfer the bookmarks. But I have a couple of questions, please see below code:

private static
void InsertBookmark(OutlineItemCollection parent, OutlineItemCollection
outlineItem, Document pdfFinal, int startingPage)

    </p><p>{

       </p><p>

OutlineItemCollection bk = new OutlineItemCollection(pdfFinal.Outlines);

        </p><p>bk.Title =

outlineItem.Title;

       </p><p> if

(outlineItem.Action != null)

        </p><p>{

GoToAction act = (GoToAction)outlineItem.Action;

            </p><p>ExplicitDestination des =

(ExplicitDestination)act.Destination;

bk.Action = new GoToAction(1);

        </p><p>}

parent.Add(bk);

}

  1. what’s difference between bk.Action and bk.Destination, I can assign the same “new GotoAction(1)” to either one and have the same bookmark effect. But in the pdf files I’m processing sometimes one has value and the other is null, so I’m not sure which one to use.

    2. I used the above code creating a new pdf with bookmarks, then when I load the created pdf into the application and found out that the des.PageNumber is 0 for my first bookmark. But if I open the pdf in acrobat reader, the property of the first bookmark is page 1. Any ideas why?

Hi Jian,


I am trying to replicate this scenario over my end and will get back to you soon. We are sorry for this delay and inconvenience.