How to Convert PDF to HTML

by Hairil Hasyimi Bin Omar

Converting PDF to HTML offers various benefits, including enhanced web accessibility for users, responsiveness for different devices, improved search engine optimization (SEO), seamless web integration, easy content editing through web-based tools and CMS, cross-platform compatibility, and the ability to utilize dynamic elements and multimedia.

IronPdf simplifies the process of converting PDF to HTML in .NET C#.


C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.

C# NuGet Library for PDF nuget.org/packages/IronPdf/
Install-Package IronPdf

Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip

Manually install into your project

Download DLL

PDF to HTML example

The ToHtmlString method is primarily designed to allow users to analyze HTML elements in an existing PDF document. It serves as a useful tool for debugging or PDF comparison purposes. In addition to converting a PDF document to HTML string, we offer a direct method for users to save a PDF document as HTML file using the SaveAsHtml method. This provides flexibility for users to choose the most suitable approach based on their specific needs.

Please note
All interactive form fields in the original PDF will no longer be functional in the resulting HTML document.

Sample PDF file

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-html.cs
using IronPdf;
using System;

PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Convert PDF to HTML string
string html = pdf.ToHtmlString();
Console.WriteLine(html);

// Convert PDF to HTML file
pdf.SaveAsHtml("myHtml.html");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Output Html

The entire output HTML generated from the SaveAsHtml method has been input into the website below.


PDF to HTML Advanced example

Both the ToHtmlString and SaveAsHtml methods offer various configuration options. Below are the available properties:

  • BackgroundColor: Specifies the background color.
  • PdfPageMargin: Specifies the page margin.

Additionally, the properties below are intended for the 'title' parameter in the ToHtmlString and SaveAsHtml methods. This will add a new title at the beginning of the content. They will not modify the title or h1 of the input PDF document.

  • H1Color: Specifies the title color.
  • H1FontSize: Specifies the title font size.
  • H1TextAlignment: Specifies the title alignment, such as left, center, or right.
:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-html-advanced-settings.cs
using IronPdf;
using IronSoftware.Drawing;
using System;

PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// PDF to HTML configuration options
HtmlFormatOptions htmlformat = new HtmlFormatOptions();
htmlformat.BackgroundColor = Color.White;
htmlformat.PdfPageMargin = 10;
htmlformat.H1Color = Color.Blue;
htmlformat.H1FontSize = 25;
htmlformat.H1TextAlignment = TextAlignment.Center;

// Convert PDF to HTML string
string html = pdf.ToHtmlString();
Console.WriteLine(html);

// Convert PDF to HTML file
pdf.SaveAsHtml("myHtmlConfigured.html", true, "Hello World", htmlFormatOptions: htmlformat);
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Output Html

The entire output HTML generated from the SaveAsHtml method has been input into the website below.

These methods will produce an HTML string with inline CSS. The output HTML uses SVG terms/tags instead of the usual HTML tags. Despite this difference, it is a valid HTML string and can be rendered the same way in a web browser. However, it's important for users to be aware that the returned HTML string from this method may differ from the HTML input when using a PDF document that was rendered using the RenderHtmlAsPdf method, due to the reasons mentioned above.

Hairil Hasyimi Bin Omar

Software Engineer

Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree in Chemical and Process Engineering.