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();
}
}
}