Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Add TOC in Existing PDF

$
0
0

Hello,

 

My team and I areattempting to add a TOC page to a merged PDF document using the example code that you posted here:

http://www.aspose.com/docs/display/pdfnet/Add+TOC+in+existing+PDF

 

While the TOC page is being generated, we believe there is an issue when the TOC page grows to be greater than 1 page. For example, we are merging many documents that can easily exceed 100 PDF pages and easily be more than 1 page of TOC. In these cases (TOC pages > 1) the linkage to the documents is not correct.

 

Some background. In our code we calculate the # of TOC pages and create a dictionary of the 1) document and the 2) respective page# that on the merged PDF. Calculating the # of TOC pages ahead of time allows us to know the exact page of a certain pdf document in the merged file. For bookmarks this is a sample of our code:

            foreach (File file in FileList)

            {

                OutlineItemCollection pdfChildOutline = new OutlineItemCollection(_doc.Outlines);

 

                // use the file name if no bookmark name is supplied

                pdfChildOutline.Title = file.fileName;               

 

                // Page # for this bookmark.

                // *** pageDictionary returns the exact page of the final merged PDF document

                pdfChildOutline.Destination = new GoToAction(pageDictionary[file.fileName]);

 

                pdfParentOutline.Add(pdfChildOutline);

            }

 

Bookmarks work just fine.  As for the TOC, the linkage is broken when TOC Pages > 1 and we cannot determine why. Can you please shed some light on how we can generate the TOC page to link them to page number AND show the page # provided inheading2.DestinationPage. Thanks, here is a snippet of the code we have for our TOC, which does not work when TOC pages > 1.

 

            for (int i = 0; i < FileList.Count; i++)

            {

                // Create Heading object

                Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);

                TextSegment segment2 = new TextSegment();

                heading2.TocPage = tocPage;

                heading2.Segments.Add(segment2);

 

                // Specify the destination page for heading object (front page of the current document)

                heading2.DestinationPage = _doc.Pages[pageDictionary[FileList[i].fileName]];

 

                segment2.Text = TGFileList[i].fileName;

 

                // Add heading to page containing TOC

                tocPage.Paragraphs.Add(heading2);

            }

 

Thanks,

Ricky Lew


This message was posted using Email2Forum by Nayyer Shahbaz.

Viewing all articles
Browse latest Browse all 3131

Trending Articles