Articles in this section
Category / Section

How to insert page number in existing PDF document ?

1 min read

How to insert page number in existing document?

Please refer to the following code example to insert the page number in existing .NET PDF document using the PdfCompositeField class.


//Load the existing PDF document
PdfLoadedDocument loadedDoc = new PdfLoadedDocument("input.pdf");
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, PdfBrushes.Black);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(font, PdfBrushes.Black);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "Page {0} of {1}", pageNumber, count);
for (int i = 0; i < loadedDoc.Pages.Count; i++)
//Draw the composite field.
compositeField.Draw(loadedDoc.Pages[i].Graphics, new PointF(loadedDoc.Pages[i].Size.Width / 2 - 20, loadedDoc.Pages[i].Size.Height - 20));
//Save the document.
//Close the document.


Sample Link:

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment