)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to insert page number in existing PDF document ?

Platform: WinForms |
Control: PDF |
Published Date: January 20, 2016 |
Last Revised Date: May 6, 2019

How to insert page number in existing document?

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

C#

//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.
loadedDoc.Save("Output.pdf");
 
//Close the document.
loadedDoc.Close(true);

 

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample1525964352

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon