How to Save a Webpage as a PDF File on Mac and Windows
Downloading web pages is a convenient way to access the content of a site for offline use. Saving a webpage in 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, and recommend a couple of alternative tools that offer basic functionality.
Saving Webpages as PDF - Getting Started
Create Your Project in Visual Studio
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.
Install the IronPDF Library
IronPDF is easy to use but it’s even easier to install. There are a couple of ways you can do it:
Method 1: NuGet Package Manager Console
In Visual Studio, in Solution Explorer, right-click References, and then click Manage NuGet Packages. Hit browse and search for ‘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 platform, 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 guidance.
Method 2: Using a DLL file
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.
Add the IronPDF Namespace
Always remember to kick off your code with the IronPDF namespace, like this:
using IronPdf;
using IronPdf;
Imports IronPdf
How to Save a Webpage as PDF using 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's what it looks like:
using IronPdf;
// Instantiate the Chrome PDF Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer()
{
RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen, // Set how CSS is rendered
PrintHtmlBackgrounds = true, // Enable printing background colors and images
EnableJavaScript = true, // Enable JavaScript execution
GrayScale = false, // Render in color
PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait, // Page orientation
PaperSize = IronPdf.Rendering.PdfPaperSize.A4, // Set paper size
MarginTop = 0,
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
UseMarginsOnHeaderAndFooter = IronPdf.UseMargins.None // Control header/footer margins
}
};
// Use Chrome Default Rendering for sizing content
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();
// Convert the webpage to a PDF
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
using IronPdf;
// Instantiate the Chrome PDF Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer()
{
RenderingOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen, // Set how CSS is rendered
PrintHtmlBackgrounds = true, // Enable printing background colors and images
EnableJavaScript = true, // Enable JavaScript execution
GrayScale = false, // Render in color
PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait, // Page orientation
PaperSize = IronPdf.Rendering.PdfPaperSize.A4, // Set paper size
MarginTop = 0,
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
UseMarginsOnHeaderAndFooter = IronPdf.UseMargins.None // Control header/footer margins
}
};
// Use Chrome Default Rendering for sizing content
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();
// Convert the webpage to a PDF
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
Imports IronPdf
' Instantiate the Chrome PDF Renderer
Private renderer As New ChromePdfRenderer() With {
.RenderingOptions = New ChromePdfRenderOptions With {
.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
}
}
' Use Chrome Default Rendering for sizing content
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering()
' Convert the webpage to a PDF
Dim pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
Then, using the SaveAs
method, you can easily save the rendered URL webpage to PDF.
// Save the rendered PDF to a file
pdf.SaveAs("example.pdf");
// Save the rendered PDF to a file
pdf.SaveAs("example.pdf");
' Save the rendered PDF to a file
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:
Add Watermarks, Password, and Headers to PDF Documents
IronPDF’s functionality doesn’t stop there, however - with our fully-equipped library, you can fine-tune and customize your presentation.
How to Add Watermarks to PDFs using IronPDF
This section shows how to add a watermark in the PDF as a stamped image, using the ApplyStamp method documentation.
// Add a watermark using an online image
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
// Add a watermark using an online image
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
' Add a watermark using an online image
pdf.ApplyStamp(New ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"))
How to Add Password Protection to PDFs using IronPDF
Adding a password to the PDF protects it from unauthorized access. You can set different passwords for users and admins to allow customization of access.
// Set a password for the PDF
pdf.Password = "EasyPassword";
// Set a password for the PDF
pdf.Password = "EasyPassword";
' Set a password for the PDF
pdf.Password = "EasyPassword"
How to Add HTML Headers to PDFs using IronPDF
Put the finishing touch on your presentation with a header, using the HtmlHeaderFooter
object.
// Add an HTML-based header to the PDF
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, // Maximum height in millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>", // Header HTML content
};
// Add an HTML-based header to the PDF
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, // Maximum height in millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>", // Header HTML content
};
' Add an HTML-based header to the PDF
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
.MaxHeight = 20,
.HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>"
}
Alternative Webpage to PDF Tools
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. 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.
Google Chrome
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
How to Convert Webpages to PDF using Google Chrome
- Open the Google Chrome dropdown menu by clicking the three dots in the top right corner
- Click Print… to open a pop-up screen
- Check that the destination is ‘Save as PDF’ and then select Save
Microsoft Edge
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.
How to Save a Webpage as a PDF using Microsoft Edge
- Open the Edge dropdown menu by clicking the three dots in the top right corner
- Click Print… and choose ‘Save to PDF’ as your Printer
- Select Save to export the webpage as PDF
Mozilla Firefox
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.
How to Save a Webpage as a PDF using Mozilla Firefox
- Open the Firefox dropdown menu by clicking the hamburger menu button (the three horizontal lines) in the top right corner
- Click Print… and choose ‘Save to PDF’ in the destination menu
- Select Save to download your PDF
Apple Safari
Like Mozilla, 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.
How to Save a Webpage as a PDF using Apple Safari
- Open the File menu at the top of the page and click Export as PDF…
- Choose a destination to save your file and click Save
Soda PDF
Soda PDF is a free online tool that 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.
How to Convert a PPT into a PDF using Soda PDF Converter
- Go to Soda PDF’s online conversion tool and enter the URL of your desired webpage
- Wait for the tool to generate your PDF
- A pop-up will appear - choose a destination for your file and click Save
Conclusion
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 that 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 for 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 affordable pricing of $749. For even bigger savings, check out the Iron Suite bundle where you can get all nine Iron Software tools for the price of two. Happy coding!