Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Downloading web pages is a convenient way to access the content of a site for offline use. And saving a webpage PDF format helps preserve the structure of the page and makes it easy to share with others.
There are many tools available which let you save a webpage as a PDF, including the browsers themselves, but sometimes you need even more control of your files. In this guide, we’ll explain how to convert web pages into PDF format using our feature-rich C# library, IronPDF, as well as recommend a couple of alternative tools which offer basic functionality.
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 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 installation page.
Always remember to kick off your code with the IronPDF namespace, like this:
using IronPdf;
using IronPdf;
Imports IronPdf
With Visual Studio open and the IronPDF library added, we begin by instantiating ChromePDFRenderer, which comes with options to customize the URL capture, including page layout, margin, and orientation of PDF pages. Then, IronPDF captures the web page as a PDF using the RenderUrlAsPdf method.
Here is what it looks like:
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer()
{
RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen,
PrintHtmlBackgrounds = true,
EnableJavaScript = true,
GrayScale = false,
PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait,
PaperSize = IronPdf.Rendering.PdfPaperSize.A4,
MarginTop = 0,
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
UseMarginsOnHeaderAndFooter = IronPdf.UseMargins.None,
}
};
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer()
{
RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen,
PrintHtmlBackgrounds = true,
EnableJavaScript = true,
GrayScale = false,
PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait,
PaperSize = IronPdf.Rendering.PdfPaperSize.A4,
MarginTop = 0,
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
UseMarginsOnHeaderAndFooter = IronPdf.UseMargins.None,
}
};
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
IRON VB CONVERTER ERROR developers@ironsoftware.com
Then, using the SaveAs method, you can easily save the rendered URL webpage to PDF.
pdf.SaveAs("example.pdf");
pdf.SaveAs("example.pdf");
pdf.SaveAs("example.pdf")
Let’s take a look at the results. Here is how the IronPDF homepage looks in Chrome:
And here is our output PDF file. You can see that, despite changing the orientation from landscape to portrait, the structure of the website is intact and still readable:
IronPDF’s functionality doesn’t stop there, however - with our fully-equipped library, you can fine-tune and customize your presentation.
This section shows how to add a watermark in the PDF as a stamped image, using the ApplyStamp method.
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.ApplyStamp(New ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"))
Adding a password to the PDF protects it from unauthorized access. You can set a different password for the user and admin to allow customization of access.
pdf.Password = "EasyPassword";
pdf.Password = "EasyPassword";
pdf.Password = "EasyPassword"
Put the finishing touch on your presentation with a header, using the HtmlHeaderFooter object.
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
IRON VB CONVERTER ERROR developers@ironsoftware.com
Saving pages using a web browser is as simple as using the built-in print menu - you just select Print in their menus or press the print button shortcut on your keyboard. And some online tools offer the PDF option when selecting a save file.
However, these options leave a lot to be desired - often breaking the structure of the webpage or missing background graphics entirely. Furthermore, there are no customization options when you save as PDF like there is with IronPDF.
Chrome is by far the most popular web browser around with an estimated 3.5 billion users worldwide. It boasts plenty of features and exporting a webpage as a PDF is one of them.
When saving a page as PDF, Chrome offers some basic options such as only saving odd, even, or multiple pages, changing paper size, and switching the layout between portrait and landscape. However, it can struggle to preserve the site’s structure, often completely changing how a page looks and making it difficult to read, as you can see in the below images:
How the webpage appears in Chrome
How Chrome renders the webpage as PDF
The successor to Microsoft’s classic Internet Explorer, Edge was updated in 2018 to run on the Chromium engine - making it very similar to Google’s Chrome browser. As such, converting webpages to PDFs is an almost identical process - with equally identical limitations.
Firefox is an alternative web browser with a focus on security and user privacy. It stands out for running on its own bespoke engine instead of Chromium. However, when it comes to saving webpages as PDFs, it works very similarly to Chrome and Edge. And like those browsers, it struggles with the layout of some pages, making the content unreadable.
Like Mozille, Apple uses its own bespoke engine to run its browser, and with it comes some slight differences compared to the other options. In our tests, Safari produced the most accurate PDF documents, but lacks features such as custom page printing selection.
Soda PDF is a free online tool which allows you to convert webpages to PDF, as well as many other features. In our tests, it proved more accurate than most other browsers, but failed to load several images from the webpage.
Web browsers and online tools are easy to use and offer a range of basic editing features. However, for a more powerful webpage to PDF conversion tool, IronPDF offers flexibility which cannot be matched.
And webpage to PDF conversions are just the start - with PDF formatting, 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. 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 even bigger savings, check out the Iron Suite where you can get all nine Iron Software tools for the price of two. Happy coding!
9 .NET API products for your office documents