PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Create PDF in C#
- Text formatting
- How to add page numbers to your PDF
- Append multiple PDF documents
- Add text field to PDF
- Convert XHTML to PDF
- Add footer with left and right aligned text on same line
- XhtmlParagraph and TrueType fonts
- What is the resulting fontsize in PDF for rich text used in a SimpleXhtmlShape
- Read and write meta data from PDF
- Merge PDF
- Stitch PDF documents
- Convert TXT to PDF
- Bulleted list from XML and XSL
- Use multiple licenses
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
How to add page numbers to your PDF
This article shows how to add page numbers to PDF using TallPDF built-in features.
We will build a simple structure based on TallPDF’s objects and using html content create a paged PDF document.
Code sample to add page numbers to PDF in C#:
private static void Main(string[] args)
{
// prepare our document
Document document = new Document();
// document may have one or more section, create one here
Section section = new Section();
document.Sections.Add(section);
// adding a fragment where page number will be generated
Fragment pagenumbers = new Fragment("#p/#P", 12);
pagenumbers.HasContextFields = true;
TextParagraph textParagraph = new TextParagraph();
textParagraph.Fragments.Add(pagenumbers);
// footer will be repeated in each page, a good place to put our page number
section.Footer = new Footer();
section.Footer.Paragraphs.Add(textParagraph);
using (FileStream inputFile = File.Open("input.html", FileMode.Open))
{
// add page content to the section here
XhtmlParagraph htmlParagraph = new XhtmlParagraph(inputFile);
section.Paragraphs.Add(htmlParagraph);
}
// save the result to PDF
using (Stream stream = new FileStream("out.pdf", FileMode.Create))
{
document.Write(stream);
}
}
Download TallPDF.NET 5.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download
We have sent an email with a download link.