Convert PDF to HTML using C#

PDF is the most popular format for sharing and printing documents. In certain cases, we may need to convert PDF documents to HTML webpages. Such conversion helps to share the content of PDF documents so that relevant stakeholders could view them in any browser easily. In this article, we will learn how to convert PDF documents to HTML webpages using C#.

The following topics shall be covered in this article:

C# API to Convert PDF to HTML — Free Download

We will be using GroupDocs.Conversion for .NET API to convert PDF to HTML. It provides fast, efficient, and reliable file conversion solutions to end-users. Please either download the DLL of the API or install it using NuGet.

Install-Package GroupDocs.Conversion

PDF to HTML Conversion using C#

We can easily convert PDF documents to HTML webpages programmatically by following the simple steps given below:

  1. Firstly, load a PDF document using the Converter class with input file path as argument. It is the main class that controls the document conversion process.
  2. Next, create an instance of the MarkupConvertOptions class. It provides various options for conversion to Markup file types.
  3. Then, optionally set various convert options such as FixedLayout, FixedLayoutShowBorders, etc.
  4. Finally, call the Converter.Convert() method to save the converted HTML file. This method takes the path of the output file and convert options as an argument.

The following code sample shows how to convert a PDF document to an HTML webpage using C#.

Convert PDF to HTML in C#.

Convert PDF to HTML in C#.

Convert Range of Pages from PDF to HTML

We can convert a range of pages of a PDF document to HTML programmatically by following the steps given below:

  1. Firstly, load a PDF document using the Converter class with input file path as argument.
  2. Next, create an instance of the MarkupConvertOptions class.
  3. Then, set page number to start conversion from
  4. After that, set pages count to convert total number of pages
  5. Finally, call the Converter.Convert() method with output file path and convert options to save the converted HTML file.

The following code sample shows how to convert a range of pages from a PDF document to an HTML file in C#.

Convert Specific Pages of PDF to HTML

We can convert specific pages of a PDF document to HTML by following the steps given below:

  1. Firstly, load a PDF document using the Converter class with input file path as argument.
  2. Next, create an instance of the MarkupConvertOptions class.
  3. Then, provide specific page numbers in a comma-separated list to convert.
  4. Finally, call the Converter.Convert() method with output file path and convert options to save the converted HTML file.

The following code sample shows how to convert specific pages of a PDF document to an HTML file in C#.

PDF to HTML Conversion with Watermark in C#

We can convert PDF documents to HTML webpages and add watermarks to converted HTML files programmatically by following the steps given below:

  1. Firstly, load a PDF document using the Converter class with input file path as argument.
  2. Next, create an instance of the WatermarkOptions class.
  3. Then, set various options such as Text, Color, Width, Height, Font, etc.
  4. Next, create an instance of the MarkupConvertOptions class.
  5. After that, assign WatermarkOptions to MarkupConvertOptions.
  6. Finally, call the Converter.Convert() method with output file path and convert options to save the converted HTML file.

The following code sample shows how to convert a PDF document to an HTML document with a watermark.

PDF to HTML Conversion with Watermark in C#.

PDF to HTML Conversion with Watermark in C#.

Get a Free License

Please try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, we have learned how to convert PDF documents to HTML webpages in C#. We have also seen how to convert specific pages of a PDF to HTML and add a watermark to the converted file programmatically. Besides, you can learn more about GroupDocs.Conversion for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also