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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I insert page numbers into an existing pdf?

Thread ID:





117958 Jan 13,2015 06:58 PM UTC Feb 6,2015 03:43 AM UTC WinForms 5
Tags: PDF
Asked On January 13, 2015 06:58 PM UTC


I'm new to syncfusion, so this might be something simple, but I just can't seem to find out how to do it.

Currently I'm able to load an existing pdf to a byte array (byte[] ba), and then put it in a PdfDocument object. From here I thought that I had to perhaps modify a template somehow to make the page numbers appear, but after an hour of looking at this I'm starting to think I'm heading in the wrong direction. Any help would be appreciated. Thanks in advance.

The code below is all I have so far.

//ba is a byte array containing an existing pdf
 Syncfusion.Pdf.Parsing.PdfLoadedDocument loadedDoc = new Syncfusion.Pdf.Parsing.PdfLoadedDocument(ba);
 PdfDocument document = new PdfDocument();

Abirami Selvan [Syncfusion]
Replied On January 14, 2015 07:35 AM UTC

Hi Andrew ,

Thank you for using Syncfusion Products.

We can add the page number into Pdf using PdfPageNumberField. Please refer the following code snippet  to add the page number in existing pdf .

//Creates a new PDF document.

PdfDocument document = new PdfDocument();

//Append the loaded document


//Sets the font.

PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f);

//Creates a brush.

PdfBrush brush = PdfBrushes.Black;

//Creates a page number field.

PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

for (int i = 0; document.pages.Count; i++)



  //Draws the page number in the document.

  pageNumber.Draw(document.Pages[i].Graphics, new PointF(250,500));


Please refer  the following link for more details


Please try this and let us know if you have any further assistance.




Replied On January 15, 2015 12:10 AM UTC

Is it possible to get it in the following format: Page X of Y where X is the current page and Y is the total number of pages?

Please take a look below. I can't seem to get anything correctly drawn below document.Pages[i].Size.Height - 130. I've slowly reduced this value to document.Pages[i].Size.Height - 126 and at every decrement, a fraction of the bottom of the text I'm drawing goes away.

//ba is a byte array containing an existing pdf
 Syncfusion.Pdf.Parsing.PdfLoadedDocument loadedDoc = new Syncfusion.Pdf.Parsing.PdfLoadedDocument(ba);
 PdfDocument document = new PdfDocument();
 string pageNums = "";

Syncfusion.Pdf.Graphics.PdfBrush brush = Syncfusion.Pdf.Graphics.PdfBrushes.Red;
Syncfusion.Pdf.Graphics.PdfFont font = new Syncfusion.Pdf.Graphics.PdfStandardFont(Syncfusion.Pdf.Graphics.PdfFontFamily.Courier, 8);

//amount of space each character will take- courier (monospace font)
 float spacePerChar = (34 / (float)7.0);
//arbitrary space buffer
 int arbitraryBuffer = 10;
            for (int i = 0; i < document.Pages.Count; i++)

                pageNums = "Page " + (i+1).ToString() + " of " + document.Pages.Count.ToString();
                System.Drawing.PointF startingPoint = new System.Drawing.PointF(document.Pages[i].Size.Width - (spacePerChar * pageNums.Length) - arbitraryBuffer, document.Pages[i].Size.Height - 126);
                document.Pages[i].Graphics.DrawString(pageNums, font, brush, startingPoint);

Abirami Selvan [Syncfusion]
Replied On January 19, 2015 07:22 AM UTC

Hi Andrew ,


We can draw the page number as  Page X(number) of Y (count) using the class  PdfCompositeField. Please refer the following code snippet :


//Adds the fields in composite fields.

PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);


for (int i = 0; i < document.Pages.Count; i++)



//Draws the composite field.

compositeField.Draw(document.Pages[i].Graphics, new PointF (document.Pages[i].GetClientSize().Width/2-20 ,document.Pages[i].GetClientSize().Height-20));



We have attached the sample for your reference . Please refer the following link :


Please try this and let us know  if you have any further assistance .


Thanks ,


Replied On February 5, 2015 01:08 AM UTC

Thanks for the response. This solution worked great!

Praveenkumar H [Syncfusion]
Replied On February 6, 2015 03:43 AM UTC

Hi Andrew,
We are happy know that the last solution worked to you.
Please let us know if you need further assistance.
With Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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