We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Indented TOC on an existing PDF Document

Hi,


Is it possible to create an indented Table of Contents to an existing PDF document?

I can create the following:-

Table Of Contents

First page…1
Second page… 2
Third page… 3
Fourth page…4

With following code:-

// Load an existing PDF files
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(“C:/temp/Excel.pdf”);

// Get access to first page of PDF file
Page tocPage = doc.Pages.Insert(1);

// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
Aspose.Pdf.Text.TextFragment title = new Aspose.Pdf.Text.TextFragment(“Table Of Contents”);
title.TextState.FontSize = 20;
title.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;

// Set the title for TOC
tocInfo.Title = title;
tocPage.TocInfo = tocInfo;

// Create string objects which will be used as TOC elements
string[] titles = new string[4];
titles[0] = “First page”;
titles[1] = “Second page”;
titles[2] = “Third page”;
titles[3] = “Fourth page”;

for (int i = 0; i < 4; i++)
{
// Create Heading object
Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
Aspose.Pdf.Text.TextSegment segment2 = new Aspose.Pdf.Text.TextSegment();
heading2.TocPage = tocPage;
heading2.Segments.Add(segment2);

// Specify the destination page for heading object
heading2.DestinationPage = doc.Pages[i + 2];

// Destination page
heading2.Top = doc.Pages[i + 2].Rect.Height;

// Destination coordinate
segment2.Text = titles[i];
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading2);
}

// Save the updated document
doc.Save(“C:/temp/TOC_Output2.pdf”);


What I want to do is add an indented TOC to an existing PDF document, something like the below:-

Table of Contents

Heading1…1
Heading1 Sub …1
Heading2 Sub …2
Heading3…3
Heading3 Sub…4
Heading4…5

Is this only possible when generating a new PDF (using the PDF Generator) and not adding a TOC to an existing PDF?


Thanks

Jon.

Hi Jon,


Thanks for your inquiry. Yes you can add TOC with different heading/level in existing PDF document as well using Aspose.Pdf. However I have noticed that the feature is malfunctioning, truncating the page number in the TOC entries. I have logged a ticket PDFNEWNET-40232 for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Thanks for the reply Tilal, could you supply some example code to do this, once the bug has been fixed.


Thanks

Jon.

Hi Jon,


Thanks for your feedback. Sure we will share the code snippet with you to accomplish the subjected task as soon as above logged issue is resolved.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-40232) have been fixed in Aspose.Pdf for .NET 11.4.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.