HiQPdf Documentation

PDF to HTML Converter

Quickly Create High Quality PDFs

With HiQPdf Library you can convert PDF pages to HTML documents using the HiQPdfPdfToHtml class. You can convert to HTML documents encapsulated in HiQPdfPdfPageHtmlCode objects in memory using the PdfToHtmlConvertToHtml(String, Int32, Int32) method or to HTML files using the PdfToHtmlConvertToHtmlFiles(String, Int32, Int32, String, String) method. There is also a special method PdfToHtmlRaisePageConvertedToHtmlEvent(String, Int32, Int32) which can be used to convert the PDF document pages to HTML one by one in memory to avoid high memory usage for large PDF documents. The HiQPdfPdfPageHtmlCode objects can be disposed when they are no longer necessary.

PDF to HTML Converter Demo

In this demo you can learn how to convert the pages of a PDF document to HTML documents. You can choose the resolution of the resulted HTML document, the zoom level and the range of PDF pages to convert to HTML.

Demo Source Code

C#
private void buttonConvertPdfToHtml_Click(object sender, EventArgs e)
{
    // get the PDF file
    string pdfFile = textBoxPdfFile.Text;
    if (pdfFile.Length == 0)
    {
        MessageBox.Show("The PDF file cannot be empty");
        return;
    }

    // create the PDF to HTML converter
    PdfToHtml pdfToHtmlConverter = new PdfToHtml();

    // set the conversion resolution in DPI
    pdfToHtmlConverter.DPI = int.Parse(textBoxDPI.Text);

    // set the zoom level
    pdfToHtmlConverter.Zoom = int.Parse(textBoxZoom.Text);

    // the output directory for resulted images
    string outputDir = Application.StartupPath + @"\DemoOut\PdfToHtml";

    Cursor = Cursors.WaitCursor;
    try
    {
        int fromPdfPageNumber = int.Parse(textBoxFromPage.Text);
        int toPdfPageNumber = textBoxToPage.Text.Length > 0 ? int.Parse(textBoxToPage.Text) : 0;

        // convert a range of pages of the PDF document to HTML documents and save the HTML documents to an output directory
        // the documents can also be produced in memory using the ConvertToHtml or RaisePageConvertedToHtmlEvent methods
        pdfToHtmlConverter.ConvertToHtmlFiles(pdfFile, fromPdfPageNumber, toPdfPageNumber, outputDir, "Page");
    }
    catch (Exception ex)
    {
        MessageBox.Show(String.Format("PDF to HTML conversion failed. {0}", ex.Message));
        return;
    }
    finally
    {
        Cursor = Cursors.Arrow;
    }

    // open the output folder in Explorer
    try
    {
        System.Diagnostics.Process.Start(outputDir);
    }
    catch (Exception ex)
    {
        MessageBox.Show(string.Format("Cannot open the output folder. {0}", ex.Message));
    }
}