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. Image for the cookie policy date
close icon

How to get "Page x of y"

Hi,
I created a PdfPageTemplateElement and added it as document.Template.Bottom; now i would print the number of each page in this way "Page x of y".
How can I get this?

1 Reply

PH Praveenkumar H Syncfusion Team November 28, 2014 05:42 AM UTC

Hi Ivan,

Thank you for using syncfusion products,

We can print the number each page in footer by using the PdfPageNumberField, PdfPageCountField and PdfCompositeField

Please refer the below code snippet to create composite field.

//Creates a new PDF document.

PdfDocument pdfDocument = new PdfDocument();

//Adds a page to the PDF document

PdfPage pdfPage = pdfDocument.Pages.Add();

pdfDocument.Pages.Add();

RectangleF rect = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);

//Footer.

//Creates a Template that can be used as footer.

//Creates a page template.

PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);

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

PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);

//Creates page number field.

PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

//Creates page count field.

PdfPageCountField count = new PdfPageCountField(font, brush);

//Adds the fields in composite fields.

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

compositeField.Bounds = footer.Bounds;

//Draws the composite field in footer.

compositeField.Draw(footer.Graphics, new PointF(470, 40));

//Adds the footer template at the bottom.

pdfDocument.Template.Bottom = footer;

//Saves the document.

MemoryStream stream = new MemoryStream();

pdfDocument.Save(stream);

pdfDocument.Close(true);

Please let us know if you need further assistance.

With Regards,

Praveen


Loader.
Live Chat Icon For mobile
Up arrow icon