|
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()); |