Save Webpage as PDF in C#

Save webpage as PDF C#

Webpages can contain text, images, drawings, animations, etc. Sometimes you might need to convert a webpage to PDF for archival or several other purposes. Accordingly, this article covers how to save or print a webpage to PDF format in C# by specifying the URL of the webpage. It discusses the simple and basic conversion as well as the advanced conversion where you can encrypt the output file.

Save Webpage as PDF File – C# API Installation

Aspose.HTML for .NET API can be used to process different web-related file formats like HTML, SVG,  EPUB, etc. You can easily configure the API by downloading its DLL files from the Downloads section or using the following NuGet installation command:

PM> Install-Package Aspose.Html

Save Webpage as PDF File in C#

You can quickly save a webpage to PDF format with the following steps:

  1. Load the input webpage by specifying its URL.
  2. Create an object of the PdfSaveOptions class.
  3. Save the webpage as a PDF file with ConvertHTML method.

The code snippet below elaborates how to save a webpage as PDF programmatically in C#:

Print Web Page to PDF with Encryption in C#

You can print a web page to PDF while securing the PDF by following the steps below:

  1. Load the input web page by using its URL.
  2. Specify the document permissions using PdfPermissions.
  3. Create PdfSaveOptions class object to encrypt the output PDF file.
  4. Write the output PDF document.

The following code sample demonstrates how to print a web page to PDF with encryption programmatically in C#:

Explore Aspose.HTML for .NET API

You can learn many other features offered by the API by visiting the documentation section.

Get Free License

You can evaluate the API in its full capacity by requesting a free temporary license.

Conclusion

In this article, you have learned how to save a webpage to PDF format by specifying its URL programmatically in C#. It explains a basic conversion use case in addition to the advanced conversion scenario. Moreover, please feel free to contact us at the forum if you need to discuss your concerns or requirements with us.

See Also

Download Image from URL in C#