Setting bounds of text when creating Table of Contents

When i create my table of contents, if the text item is too long it runs over th epage numbering to the right. Can we set a maximum width of page width - 45??

My code for adding the titile elements to Table of Contents is as follows:

    Private Function AddTableOfContent(ByVal tocPage As PdfPage, ByVal content As String, ByVal points As PointF) As PdfLayoutResult
        Dim element As PdfTextElement = New PdfTextElement(content, Font, PdfBrushes.Black)
        Dim format As PdfLayoutFormat = New PdfLayoutFormat()
        format.Break = PdfLayoutBreakType.FitPage
        format.Layout = PdfLayoutType.Paginate
        Dim result As PdfLayoutResult = element.Draw(tocPage, points)
        Return result
    End Function

I add the page numebr after using this:

    Private Sub AddPageNumberInTOC(ByVal pageNumberPosition As List(Of TOCPageNumbers), ByVal pageNumber As List(Of Integer))
        Dim count As Integer = 0
        For i As Integer = 0 To pageNumberPosition.Count - 1
            Dim ppagecount As Integer = pageNumber.Count
            Dim pagepos As Integer = pageNumberPosition.Count
            Dim points As PointF = pageNumberPosition(i).COord
            Dim page As PdfPage = pageNumberPosition(i).PDFPage
            page.Graphics.DrawString((pageNumber(count) + 1).ToString(), Font, PdfBrushes.Black, New PointF(page.Graphics.ClientSize.Width - 40, points.Y))
            Dim bounds As RectangleF = New RectangleF(points.X, points.Y, page.Graphics.ClientSize.Width - points.X, 10)
            Dim documentLinkAnnotation As PdfDocumentLinkAnnotation = New PdfDocumentLinkAnnotation(bounds)
            documentLinkAnnotation.AnnotationFlags = PdfAnnotationFlags.NoRotate
            documentLinkAnnotation.Color = Color.Transparent
            documentLinkAnnotation.Destination = New PdfDestination(document.Pages(pageNumber(count)))
            documentLinkAnnotation.Destination.Location = PointF.Empty
            page.Annotations.Add(documentLinkAnnotation)
            count += 1
        Next
    End Sub

1 Reply 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team November 2, 2020 09:54 AM UTC

Hi Martin,   
  
Thank you for contacting Syncfusion support.   
  
We have analyzed your requirement and we can able to set the width of the given text using PdfStringLayoutResult. Please refer the below documentation for more details,   
  
Also we can able to set the size of the PDF page and please refer the below code for more details,    
//Create a new PDF document  
PdfDocument document = new PdfDocument();  
  
//Set the page size  
document.PageSettings.Size = new SizeF(450,500);  
  
//Add a page to the document  
PdfPage page = document.Pages.Add(); 

If you still facing the issue, please provide us the below details. It will helpful for us to provide the precise solution on this.   
  
  • Expected output
  • Sample / complete code snippet
  
Regards,  
Sowmiya Loganathan 


Marked as answer
Loader.
Up arrow icon