Convert PDF to HTML in .NET Smart Data Extractor

7 Oct 20265 minutes to read

HTML is a widely used format for structuring and presenting content on the web. The Syncfusion® Smart Data Extractor library supports PDF and image to HTML conversion in .NET, enabling seamless transformation of PDF files into clean, well-structured HTML markup while preserving the original layout, barcodes, tables, and images. This feature makes it easier to reuse content, improve accessibility, and integrate document data into .NET applications and business workflows.

Assemblies and NuGet packages required

Refer to the following links for the assemblies and NuGet packages required based on your target platform to convert a PDF or image as an HTML file using the Syncfusion® Smart Data Extractor library.

Convert PDF or image to HTML Document

To convert a PDF document or image into HTML output using the ExtractDataAsHtml method of the DataExtractor class, refer to the following code example.

using Syncfusion.SmartDataExtractor;

//Open the input PDF file as a stream.
using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{
  //Initialize the Data Extractor.
  DataExtractor extractor = new DataExtractor();
  //Extract data as HTML.
  string htmlContent = extractor.ExtractDataAsHtml(stream);
  //Save the extracted data into the HTML file.
  File.WriteAllText("Output.html", htmlContent);
}
using Syncfusion.SmartDataExtractor;

//Open the input PDF file as a stream.
using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{
  //Initialize the Data Extractor.
  DataExtractor extractor = new DataExtractor();
  //Extract data as HTML.
  string htmlContent = extractor.ExtractDataAsHtml(stream);
  //Save the extracted data into the HTML file.
  File.WriteAllText("Output.html", htmlContent);
}

To convert an image instead of a PDF, replace the input stream with the image file (for example, Input.jpg or Input.png). The rest of the code remains unchanged.

You can download a complete working sample from GitHub.

Convert a range of PDF pages to HTML

To convert a specific range of PDF pages from the PDF document into HTML using the ExtractDataAsHtml method of the DataExtractor class, refer to the following code example.

using Syncfusion.SmartDataExtractor;

//Open the input PDF file as a stream.
using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{
  //Initialize the Data Extractor.
  DataExtractor extractor = new DataExtractor();
  //Set the page range for conversion (example: pages 2 to 4).
  extractor.PageRange = new int[,] { { 2, 4 } };
  //Extract data as HTML.
  string htmlContent = extractor.ExtractDataAsHtml(stream);
  //Save the extracted data into the HTML file.
  File.WriteAllText("Output.html", htmlContent);
}
using Syncfusion.SmartDataExtractor;

//Open the input PDF file as a stream.
using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{
  //Initialize the Data Extractor.
  DataExtractor extractor = new DataExtractor();
  //Set the page range for conversion (example: pages 2 to 4).
  extractor.PageRange = new int[,] { { 2, 4 } };
  //Extract data as HTML.
  string htmlContent = extractor.ExtractDataAsHtml(stream);
  //Save the extracted data into the HTML file.
  File.WriteAllText("Output.html", htmlContent);
}

To convert an image instead of a PDF, replace the input stream with the image file (for example, Input.jpg or Input.png). The rest of the code remains unchanged.

Supported and Unsupported PDF Elements

The following table lists the PDF elements and their preservation details in the HTML output.

PDF Elements Supported
Header, Paragraph Title, Document Title Yes
Image Yes
Table Yes
Text Inline Styles Yes (Bold and Italic)
Subscript, Superscript No
Underline, Strikethrough No
List No (Converted as line-by-line text)
Charts and Barcodes Yes (Preserved as images)
Code blocks, Footer, Page Number Yes (Preserved as text)
Link No (Preserved as plain text)