Hello,
I’m trying to dynamically create a table of contents and I am getting the oddest styling error.
What I’m seeing is that a few of the rows are out of alignment. For example,
Title
Page 1
Page 2
Page 3
instead of
Title
Page 1
Page 2
Page 3
I’ve tried a bunch of different settings to try and get it to align but it doesn’t want to play ball (such as setting default margins, removing character spacing etc). Is anyone else getting this problem? I attached the function used to create the TOC below.
Thanks :=)
public void InsertIndexPage(string sourcePath, string destPath, Dictionary<int, string> pageIndexes)
{
PdfFileEditor pdfEditor = new PdfFileEditor();
Aspose.Pdf.
Document pdfDocument = new Aspose.Pdf.Document(sourcePath);
// Get access to first page of PDF file
Page tocPage = pdfDocument.Pages.Insert(1);
// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
TextFragment title = new TextFragment("Table Of Contents");
title.TextState.FontSize = 20;
title.TextState.FontStyle =
FontStyles.Bold;
// Set the title for TOC
tocInfo.Title = title;
tocPage.TocInfo = tocInfo;
// loop through pageIndexes
foreach (var pageIndex in pageIndexes)
{
// 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
heading2.DestinationPage = pdfDocument.Pages[pageIndex.Key + 1];
// Destination page
heading2.Top = pdfDocument.Pages[pageIndex.Key + 1].Rect.Height;
// Destination coordinate
segment2.Text =
"Whatever"
// format
heading2.Margin.Top = 5;
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading2);
}
pdfDocument.Save(destPath);
}