HTML to PDF Byte Array (.NET Core/Framework)

How to Convert HTML to PDF Byte Array in C#

The following steps and sample code illustrate how to quickly convert HTML to a PDF byte array using the DynamicPDF HTML Converter product. Basic HTML to PDF conversion can be done with one method call, however, if required advanced ConversionOptions class can be used.

Steps for Creating a PDF Document from HTML

  1. Reference DynamicPDF HTML Converter from Nuget (ID: ceTe.DynamicPDF.HtmlConverter.NET).
  2. Add a using statement for ceTe.DynamicPDF.HtmlConverter.
  3. Invoke the Convert method on the HtmlConverter and specify the PDF file name.

Sample Code - C#

byte[] pdfByteArray = Converter.Convert(new Uri("https://www.google.com"));
// Write the bytes to disk, or you can do whatever you need to with them
File.WriteAllBytes("ConvertToByteArray.pdf", pdfByteArray);

Getting Started

NuGet Package

DynamicPDF HTML Converter is available on NuGet in the ceTe.DynamicPDF.HtmlConverter.NET package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download directly from NuGet.

NuGet Package ID: ceTe.DynamicPDF.HtmlConverter.NET

Example Project

An example project showing the functionality on this page can be cloned or viewed from GitHub:

Clone or View Example Project on GitHub

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!