Posted by a ceTe Software moderator
Hello,
There is no automatic way to generate dots while adding table of contents. Below is the pseudo code that shows how to keep track of the horizontal width and add a label with a dynamic number of dots for each line in the table of contents.
Dim document As ceTe.DynamicPDF.Document = New Document()
document.Pages.Add(New Page())
Dim titles() As String = {"very long name", "very very very loooooooonnnnggggggg name", "short name", "name", "very very long name"}
Dim i As Int32 = 0
Dim y As Int32 = 0
For Each value As String In titles
'create a label and set the width exactly to what is needed to display it.
Dim lbl As Label = New Label(value, 0, y, 100, 15, Font.Courier, 12)
lbl.Width = lbl.Font.GetTextWidth(value, lbl.FontSize)
'create a label with dots and dynamically add dots based on the horizontal space left.
Dim dots As String = "."
Dim dotsWidth = document.Pages(0).Dimensions.Body.Width - lbl.Width - 20
While dotsWidth >= Font.Courier.GetTextWidth(dots, 12)
dots = dots + "."
End While
Dim lblDots As Label = New Label(dots, lbl.Width, y, dotsWidth, 15, Font.Courier, 12)
' add all labels to the page.
document.Pages(0).Elements.Add(lblDots)
document.Pages(0).Elements.Add(lbl)
document.Pages(0).Elements.Add(New Label(i, lbl.Width + dotsWidth, y, 20, 15, Font.Courier, 12)) 'page number label
i = i + 1
y = y + 20
Next
'save the document
document.Draw("out.pdf")
Thanks,
ceTe Software Support Team.