Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
PDFs are everywhere - and for good reason. They’re secure, easy to share, and work on just about any machine or browser in the world. However, despite millions of people using PDF files every day, they can still be tricky to properly use.
One of the best features of PDF documents is that they’re hard to tamper with, but that gets in the way when you’re looking to make some changes of your own. In this guide, we’ll show how easy it is to add page numbers to a PDF file using our feature-rich C# library, IronPDF, as well as recommend a couple of alternative online tools which offer basic functionality.
IronPDF is a lightweight .NET PDF library designed specifically with web developers in mind. PDF conversion is just one of many uses - it makes reading, writing, and manipulating PDFs a breeze, and you can use it in your .NET projects for both desktop and web. The best part - it’s free to try out in a development environment.
One of the main advantages of IronPDF is its flexibility. It can be used as a standalone desktop application or integrated into your web application using the IronPDF API. Additionally, IronPDF is compatible with Windows, Mac, and Linux operating systems, making it accessible to a wide range of users.
First of all, open Visual Studio and go to File -> New Project -> Console Application. Enter your project name, choose the location you want to save it to, and hit the Next button. Select the latest .NET Framework and then Create. Once your project is up and running, it’s time to add our library.
IronPDF is easy to use but it’s even easier to install. There are a couple of ways you can do it:
In Visual Studio, in Solution Explorer, right-click References, and then click Manage NuGet Packages. Hit browse and search ‘IronPDF, and install the latest version. If you see this, it’s working:
You can also go to Tools -> NuGet Package Manager -> Packet Manager Console, and enter the following line in the Package Manager Tab:
Install-Package IronPdf
Finally, you can get IronPDF directly from NuGet’s official website. Select the Download Package option from the menu on the right of the IronPDF NuGet page, double-click your download to install it automatically, and reload the Solution to start using it in your project.
Didn’t work? You can find platform-specific help on our advanced NuGet installation page.
You can also get the IronPDF DLL file straight from us and add it to Visual Studio manually. For full instructions and links to the Windows, macOS, and Linux DLL packages, check out our dedicated IronPDF installation guide.
Always remember to kick off your code with the IronPDF namespace, like this:
using IronPdf;
using IronPdf;
Imports IronPdf
We kick things off by importing the IronPDF package and then creating an HTML string which will be converted to PDF with page numbers. Here’s the code example:
using IronPdf;
var html = @"
<p> Hello Iron</p>
<p> This is 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> This is 2nd Page</p>
<div style = 'page-break-after: always;' ></div>
<p> This is 3rd Page</p>";
using IronPdf;
var html = @"
<p> Hello Iron</p>
<p> This is 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> This is 2nd Page</p>
<div style = 'page-break-after: always;' ></div>
<p> This is 3rd Page</p>";
IRON VB CONVERTER ERROR developers@ironsoftware.com
Next, we’ll instantiate ChromePDFRender with specific HTML footer settings. This allows us to define the styling and layout of the page numbers in our PDF. Here’s the code:
// Instantiate Renderer
var renderer = new ChromePdfRenderer
{
RenderingOptions =
{
HtmlFooter = new HtmlHeaderFooter()
{
MaxHeight = 15, // millimeters
HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
DrawDividerLine = true
}
}
};
// Instantiate Renderer
var renderer = new ChromePdfRenderer
{
RenderingOptions =
{
HtmlFooter = new HtmlHeaderFooter()
{
MaxHeight = 15, // millimeters
HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
DrawDividerLine = true
}
}
};
' Instantiate Renderer
Dim renderer = New ChromePdfRenderer With {
.RenderingOptions = {
HtmlFooter = New HtmlHeaderFooter() With {
.MaxHeight = 15,
.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>",
.DrawDividerLine = True
}
}
}
Then, we’ll render the HTML as a PDF. Simply call the RenderHtmlAsPdf method to convert it to PDF and IronPDF will automatically add numbers to each page.
var pdf = renderer.RenderHtmlAsPdf(html);
var pdf = renderer.RenderHtmlAsPdf(html);
Dim pdf = renderer.RenderHtmlAsPdf(html)
And finally, all we need to do now is save the newly numbered PDF to our system. It’s as simple as this:
pdf.SaveAs("pageNumber.pdf");
pdf.SaveAs("pageNumber.pdf");
pdf.SaveAs("pageNumber.pdf")
As you saw in the code before, we customized our page number format to be centered on the page, to show the current and total number of pages, and add a divider line. Here’s what the final product looks like:
There are many free, if limited, tools which allow you to add page numbers to PDFs. Here are some alternative PDF page numbering options.
Sejda PDF Editor is an online tool which offers basic PDF editing tools such as merging pages, compressing the file size, creating forms, and more. While it is free to use, it comes with page and time restrictions before you have to subscribe to one of the paid plans.
SmallPDF is a popular online tool that offers a range of PDF editing features, including the ability to add page numbers. One of the main advantages of SmallPDF is its convenience. Because it is a web-based tool, you can access it from any device with an internet connection, without needing to download or install any software.
Adding page numbers to PDF documents is a straightforward way to improve the readability and organization of your document. It’s a simple task, but one which different tools approach in various ways and with a range of features and options.
Free online tools can be quick and convenient, until you hit the limit and need to subscribe to a plan, but they can lack the in-depth control which a dedicated PDF library - like IronPDF - provides.
And PDF page numbers are just the start - with PDF formatting tools, built-in security and compliance features, and more, IronPDF is the number one tool for all of your PDF document needs.
Ready to get your hands on IronPDF? You can start with our 30-day free trial of IronPDF. It’s also completely free to use for development purposes so you can really get to see what it’s made of. And if you like what you see, IronPDF starts as low as $749 for a license. For even bigger savings, check out the Iron Suite deal where you can get all nine Iron Software tools for the price of two. Happy coding!
9 .NET API products for your office documents