PDF TOOLS

How to Save a Webpage as a PDF File on Mac and Windows

Updated August 13, 2024
Share:

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.

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 ‘IronPDF, and install the latest version. If you see this, it’s working:

How to Save a Webpage as a PDF File on Mac and Windows: Figure 1

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.

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 installation page.

Add the IronPDF Namespace

Always remember to kick off your code with the IronPDF namespace, like this:

using IronPdf;
using IronPdf;
Imports IronPdf
VB   C#

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 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
VB   C#

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")
VB   C#

Let’s take a look at the results. Here is how the IronPDF homepage looks in Chrome:

How to Save a Webpage as a PDF File on Mac and Windows: Figure 2

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:

How to Save a Webpage as a PDF File on Mac and Windows: Figure 3

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.

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"))
VB   C#

How to Add Password Protection to PDFs using IronPDF

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"
VB   C#

How to Add HTML Headers to PDFs using IronPDF

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
VB   C#

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. 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.

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 to Save a Webpage as a PDF File on Mac and Windows: Figure 4

How the webpage appears in Chrome

How to Save a Webpage as a PDF File on Mac and Windows: Figure 5

How Chrome renders the webpage as PDF

How to Convert Webpages to PDF using Google Chrome

  • Open the Google Chrome drop down 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 drop down 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 drop down 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 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.

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 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.

How to Convert a PPT into a PDF using Soda PDF Converter

  • Go to Soda PDF 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 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!

How to Save a Webpage as a PDF File on Mac and Windows: Figure 6

< PREVIOUS
Best PDF Viewer Options in 2022
NEXT >
How to Extract Pages from PDF Files — a Step-By-Step Guide

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 11,308,499 View Licenses >