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

Free Support Forum - aspose.com

Could not align the page numbers in TOC to right justified

Hi,

Is there an option to align the page numbers in TOC to right justified?

Please let me know the property / method to do that.

I have attached the image of the TOC generated and marked the alignment issue in red, for better understanding about the issue.

Thanks,

Gilbert

Hi,

Thank you for considering Aspose.

Can you please tell me are you using ListSection or using Heading to create Table of Contents. In case of Heading you can set 'Heading.LabelWidth' property.

Thanks.

Dear Gilbert,

If it sitll won’t work please provide your code that can reproduce this error.

The code that adds TOC section:

Private Sub AddTOC(ByRef priceBookPDF As Pdf)

'Create a ListSection for Table of Contents

Dim tocSection As ListSection = New ListSection(priceBookPDF)

tocSection.ListType = ListType.TableOfContents

'Set the title as 'Table of Contents' and set the font information for the title

tocSection.Title = New Text("Table of Contents")

tocSection.Title.Margin.Bottom = 30 'points

tocSection.Title.TextInfo.Alignment = AlignmentType.Center

tocSection.Title.TextInfo.FontName = "Verdana"

tocSection.Title.TextInfo.FontSize = 20 'points

tocSection.Title.TextInfo.IsTrueTypeFontBold = True

'Add the Table of Contents section to the pdf document

priceBookPDF.Sections.Add(tocSection)

'Define the format of levels list by setting the left margins and

'text format settings of each level

tocSection.ListFormatArray.Length = 3

Dim marginLevelOne As MarginInfo = New MarginInfo()

marginLevelOne.Left = 0 'points

tocSection.ListFormatArray(0).Margin = marginLevelOne

tocSection.ListFormatArray(0).TabLeaderType = TabLeaderType.Dot

tocSection.ListFormatArray(0).TextInfo.LineSpacing = 12

tocSection.ListFormatArray(0).TextInfo.FontName = "Verdana"

tocSection.ListFormatArray(0).TextInfo.FontSize = 14

'tocSection.ListFormatArray(0).TextInfo.IsTrueTypeFontBold = True

Dim marginLevelTwo As MarginInfo = New MarginInfo()

marginLevelTwo.Left = 20 'points

tocSection.ListFormatArray(1).Margin = marginLevelTwo

tocSection.ListFormatArray(1).TabLeaderType = TabLeaderType.Dot

tocSection.ListFormatArray(1).TextInfo.LineSpacing = 9

tocSection.ListFormatArray(1).TextInfo.FontName = "Verdana"

tocSection.ListFormatArray(1).TextInfo.FontSize = 12

tocSection.ListFormatArray(1).TextInfo.IsTrueTypeFontBold = True

Dim marginLevelThree As MarginInfo = New MarginInfo()

marginLevelThree.Left = 40 'points

tocSection.ListFormatArray(2).Margin = marginLevelThree

tocSection.ListFormatArray(2).TabLeaderType = TabLeaderType.Dot

tocSection.ListFormatArray(2).TextInfo.LineSpacing = 6

tocSection.ListFormatArray(2).TextInfo.FontName = "Verdana"

tocSection.ListFormatArray(2).TextInfo.FontSize = 10

'tocSection.ListFormatArray(2).TextInfo.IsTrueTypeFontItalic = True

End Sub

The code that adds bookmarks:

Private Sub BookmarkFamilyAndPanel(ByRef priceBookPDF As Pdf, ByRef contentSection As Section, ByVal doorFamily As String, ByVal panelType As String)

'Create the Bookmark for display and link in the Table of Contents.

'It should not be visible because it will be displayed twice as it is

'already present in the header. So make the font size 1 and color white.

Dim famHeading As Heading = New Heading(priceBookPDF, contentSection, 2)

Dim famSegment As Segment = New Segment(famHeading)

famHeading.Segments.Add(famSegment)

famSegment.Content = doorFamily

famSegment.TextInfo.FontSize = 1

famSegment.TextInfo.Color = New Color("#ffffff")

'Added in the Table of contents

famHeading.IsInList = True

'Keep next paragraph together

famHeading.IsKeptWithNext = True

contentSection.Paragraphs.Add(famHeading)

BookmarkPanel(priceBookPDF, contentSection, panelType)

End Sub

Private Sub BookmarkPanel(ByRef priceBookPDF As Pdf, ByRef contentSection As Section, ByVal panelType As String)

'Create the Bookmark for display and link in the Table of Contents.

'It should not be visible because it will be displayed twice as it is

'already present in the header. So make the font size 1 and color white.

Dim panHeading As Heading = New Heading(priceBookPDF, contentSection, 3)

Dim panSegment As Segment = New Segment(panHeading)

panSegment.TextInfo.FontSize = 1

panSegment.TextInfo.Color = New Color("#ffffff")

panHeading.Segments.Add(panSegment)

panSegment.Content = panelType

'Added in the Table of contents

panHeading.IsInList = True

contentSection.Paragraphs.Add(panHeading)

End Sub

Private Sub BookmarkOthers(ByRef priceBookPDF As Pdf, ByRef section As Section, ByVal text As String)

'Create the Bookmark for display and link in the Table of Contents.

'It should not be visible because it will be displayed twice as it is

'already present in the header. So make the font size 1 and color white.

Dim heading As Heading = New Heading(priceBookPDF, section, 1)

Dim segment As Segment = New Segment(heading)

heading.Segments.Add(segment)

segment.Content = text

heading.IsFirstParagraph = True

heading.TextInfo.FontSize = 1

heading.TextInfo.Color = New Color("#ffffff")

'Added in the Table of contents

heading.IsInList = True

'Keep next paragraph together

heading.IsKeptWithNext = True

section.Paragraphs.Add(heading)

End Sub

I have reproduced this error and logged this issue as PDFNET-4020. We will try to fix this bug in the future version.