How to insert page number in existing PDF document in WinForms?
Please refer to the following code example to insert the page number in existing .NET 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:
Conclusion
I hope you enjoyed learning about how to insert page number in existing PDF document in WinForms.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!