How to convert PDF to HTML with/without CSS in ASP.NET with PDF To HTML SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to convert PDF to HTML with/without CSS in ASP.NET with PDF To HTML SDK

  • Home
  • /
  • Articles
  • /
  • How to convert PDF to HTML with/without CSS in ASP.NET with PDF To HTML SDK

This sample shows PDF to HTML conversion in ASP.NET using Bytescout PDF To HTML SDK.

You can select from two options:

Convert PDF to HTML (simple layout)

using System;
using Bytescout.PDF2HTML;

namespace ExtractHTML
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			// This test file will be copied to the project directory on the pre-build event (see the project properties).
			String inputFile = Server.MapPath("sample2.pdf");

			// Create Bytescout.PDFExtractor.HTMLExtractor instance
			HTMLExtractor extractor = new HTMLExtractor();
			extractor.RegistrationName = "demo";
			extractor.RegistrationKey = "demo";

			// Set plain HTML extraction mode
			extractor.ExtractionMode = HTMLExtractionMode.PlainHTML;
			
			// Load sample PDF document
			extractor.LoadDocumentFromFile(inputFile);

			Response.Clear();
			Response.ContentType = "text/html";

			// Save extracted text to output stream
			extractor.SaveHtmlToStream(Response.OutputStream);

			Response.End();

			extractor.Dispose();
		}
	}
}

Convert PDF to HTML (with layout)

using System;
using Bytescout.PDF2HTML;

namespace ExtractHTML
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			// This test file will be copied to the project directory on the pre-build event (see the project properties).
			String inputFile = Server.MapPath("sample2.pdf");

			// Create Bytescout.PDF2HTML.HTMLExtractor instance
			HTMLExtractor extractor = new HTMLExtractor();
			extractor.RegistrationName = "demo";
			extractor.RegistrationKey = "demo";

			// Set HTML with CSS extraction mode
			extractor.ExtractionMode = HTMLExtractionMode.HTMLWithCSS;
			
			// Load sample PDF document
			extractor.LoadDocumentFromFile(inputFile);

			Response.Clear();
			Response.ContentType = "text/html";

			// Save extracted text to output stream
			extractor.SaveHtmlToStream(Response.OutputStream);

			Response.End();

			extractor.Dispose();
		}
	}
}

Tutorials:

prev
next