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

How to get "Page x of y"

Thread ID:

Created:

Updated:

Platform:

Replies:

117676 Nov 26,2014 02:18 PM UTC Nov 28,2014 05:42 AM UTC Xamarin.Forms 1
loading
Tags: PDF
Ivan
Asked On November 26, 2014 02:18 PM UTC

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?

Praveenkumar H [Syncfusion]
Replied On 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


CONFIRMATION

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.

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

;