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.