Adding "." inbetween content and pagenumber in Table of Contents.

I was unable to figure how to add ".................." in TOC between the content and page nos.

eg: 

Content ................................................................................1

Content..................................................................................2

kindly do the need.


1 Reply

PV Prakash Viswanathan Syncfusion Team November 4, 2021 08:05 AM UTC

Hi Vignesh, 

Thank you for contacting Syncfusion support. 

To add the dots between the content and page number, we have to measure the size of the content using measure string function. Using the content starting location and content size, we need to draw the dots manually in a for loop until reaching the page number location.  

Please refer below links for more information, 

Please refer the below simple sample code, 
string content = "TOC content"; 
float x = 10; 
float y = 40; 
PdfDocument document = new PdfDocument(); 
document.PageSettings.Margins.All = 0; 
 
int pageNumber = 1; 
PdfPage page = document.Pages.Add(); 
 
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11); 
 
//Draw content 
page.Graphics.DrawString(content, font, PdfBrushes.Black, x, y); 
 
float dotStartPosition = font.MeasureString(content).Width; 
float dotEndPostion = font.MeasureString(pageNumber.ToString()).Width; 
 
for (float i = dotStartPosition; (x + i) < (page.GetClientSize().Width - 15 - dotEndPostion); i = i + 2) 
{ 
     //Adding dots 
     page.Graphics.DrawString(".", font, PdfBrushes.Black, (x + i) , y); 
} 
 
//Draw page number 
page.Graphics.DrawString(pageNumber.ToString(), font, PdfBrushes.Black, page.GetClientSize().Width - 15, y); 
 
MemoryStream stream = new MemoryStream(); 
 
document.Save(stream); 
document.Close(); 
 
File.WriteAllBytes("Sample.pdf", stream.ToArray()); 

Regards, 
Prakash V 


Loader.
Up arrow icon