> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/pdf2htmltest.md).

# Convert PDF to HTML with Apryse Server SDK: Sample Code in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go, and VB

Sample code for using Apryse SDK to convert generic PDF documents to HTML format, provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.

Sample code for using Apryse SDK to programmatically convert generic PDF documents to HTML, provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB. Learn more about our [PDF to HTML](/core/conversion/convert-pdf-to-html.md)

To run this sample, you will need to:

1. [Get started with Server SDK](/core/get-started/get-started.md) in your language/framework
2. Download the[ ](/core/learn-more/modules.md#data-extraction-module)[Structured Output Module](/core/learn-more/modules.md#structured-output-module)

Learn more about our [Server SDK](/core/get-started/get-started.md).

{% tabs %}
{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <iostream>
#include <sstream>
#include <PDF/PDFNet.h>
#include <PDF/Convert.h>
#include <PDF/StructuredOutputModule.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to HTML.
//
// There are two HTML modules and one of them is an optional PDFNet Add-on.
// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
//    documents.
// 2. The optional add-on module is used to convert PDF documents to HTML documents with
//    text flowing across the browser window.
//
// The Apryse SDK HTML add-on module can be downloaded from http://www.pdftron.com/
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

using namespace pdftron;
using namespace PDF;
using namespace std;

UString inputPath("../../TestFiles/");
UString outputPath("../../TestFiles/Output/");

int main(int argc, char *argv[])
{	
	// The first step in every application using PDFNet is to initialize the 
	// library. The library is usually initialized only once, but calling 
	// Initialize() multiple times is also fine.
	PDFNet::Initialize(LicenseKey);

	int err = 0;

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to HTML with fixed positioning option turned on (default)
		cout << "Converting PDF to HTML with fixed positioning option turned on (default)" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_fixed_positioning";

		// Convert PDF to HTML
		Convert::ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to HTML, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	PDFNet::AddResourceSearchPath("../../../Lib/");

	if (!StructuredOutputModule::IsModuleAvailable())
	{
		cout << endl;
		cout << "Unable to run part of the sample: Apryse SDK Structured Output module not available." << endl;
		cout << "-------------------------------------------------------------------------------------" << endl;
		cout << "The Structured Output module is an optional add-on, available for download" << endl;
		cout << "at https://docs.apryse.com/core/guides/info/modules . If you have already" << endl;
		cout << "downloaded this module, ensure that the SDK is able to find the required files" << endl;
		cout << "using the PDFNet::AddResourceSearchPath() function." << endl;
		cout << endl;
		return 0;
	}

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to HTML with reflow full option turned on (1)
		cout << "Converting PDF to HTML with reflow full option turned on (1)" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_reflow_full.html";

		Convert::HTMLOutputOptions htmlOutputOptions;

		// Set e_reflow_full content reflow setting
		htmlOutputOptions.SetContentReflowSetting(Convert::HTMLOutputOptions::e_reflow_full);

		// Convert PDF to HTML
		Convert::ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to HTML, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
		cout << "Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_reflow_full_first_page.html";

		Convert::HTMLOutputOptions htmlOutputOptions;

		// Set e_reflow_full content reflow setting
		htmlOutputOptions.SetContentReflowSetting(Convert::HTMLOutputOptions::e_reflow_full);

		// Convert only the first page
		htmlOutputOptions.SetPages(1, 1);

		// Convert PDF to HTML
		Convert::ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to HTML, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	PDFNet::Terminate();
	cout << "Done.\n";
	return err;
}
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
//

using System;
using pdftron;
using pdftron.Common;
using pdftron.PDF;

namespace PDF2HtmlTestCS
{
	/// <summary>
	// The following sample illustrates how to use the PDF::Convert utility class to convert 
	// documents and files to HTML.
	//
	// There are two HTML modules and one of them is an optional PDFNet Add-on.
	// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
	//    documents.
	// 2. The optional add-on module is used to convert PDF documents to HTML documents with
	//    text flowing across the browser window.
	//
	// The Apryse SDK HTML add-on module can be downloaded from http://www.pdftron.com/
	//
	// Please contact us if you have any questions.	
	/// </summary>

	class Class1
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();

		static Class1() { }

		// Relative path to the folder containing test files.
		const string inputPath = "../../../../TestFiles/";
		const string outputPath = "../../../../TestFiles/Output/";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
			// The first step in every application using PDFNet is to initialize the 
			// library. The library is usually initialized only once, but calling 
			// Initialize() multiple times is also fine.
			PDFNet.Initialize(PDFTronLicense.Key);

			bool err = false;

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to HTML with fixed positioning option turned on (default)
				Console.WriteLine("Converting PDF to HTML with fixed positioning option turned on (default)");

				string outputFile = outputPath + "paragraphs_and_tables_fixed_positioning";

				pdftron.PDF.Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to HTML, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			PDFNet.AddResourceSearchPath("../../../../../Lib/");

			if (!StructuredOutputModule.IsModuleAvailable())
			{
				Console.WriteLine();
				Console.WriteLine("Unable to run part of the sample: Apryse SDK Structured Output module not available.");
				Console.WriteLine("-------------------------------------------------------------------------------------");
				Console.WriteLine("The Structured Output module is an optional add-on, available for download");
				Console.WriteLine("at https://docs.apryse.com/core/guides/info/modules . If you have already");
				Console.WriteLine("downloaded this module, ensure that the SDK is able to find the required files");
				Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
				Console.WriteLine();
				return 0;
			}

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to HTML with reflow full option turned on (1)
				Console.WriteLine("Converting PDF to HTML with reflow full option turned on (1)");

				string outputFile = outputPath + "paragraphs_and_tables_reflow_full.html";

				pdftron.PDF.Convert.HTMLOutputOptions htmlOutputOptions = new pdftron.PDF.Convert.HTMLOutputOptions();

				// Set e_reflow_full content reflow setting
				htmlOutputOptions.SetContentReflowSetting(pdftron.PDF.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);

				pdftron.PDF.Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to HTML, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
				Console.WriteLine("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)");

				string outputFile = outputPath + "paragraphs_and_tables_reflow_full_first_page.html";

				pdftron.PDF.Convert.HTMLOutputOptions htmlOutputOptions = new pdftron.PDF.Convert.HTMLOutputOptions();

				// Set e_reflow_full content reflow setting
				htmlOutputOptions.SetContentReflowSetting(pdftron.PDF.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);

				// Convert only the first page
				htmlOutputOptions.SetPages(1, 1);

				pdftron.PDF.Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to HTML, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			PDFNet.Terminate();
			Console.WriteLine("Done.");
			return (err == false ? 0 : 1);
		}
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to HTML.
//
// There are two HTML modules and one of them is an optional PDFNet Add-on.
// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
//    documents.
// 2. The optional add-on module is used to convert PDF documents to HTML documents with
//    text flowing across the browser window.
//
// The PDFTron SDK HTML add-on module can be downloaded from http://www.pdftron.com/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

// Relative path to the folder containing the test files.
var inputPath = "../../TestFiles/"
var outputPath = "../../TestFiles/Output/"

//---------------------------------------------------------------------------------------

func catch(err *error) {
    if r := recover(); r != nil {
        *err = fmt.Errorf("%v", r)
    }
}

//---------------------------------------------------------------------------------------

func ConvertToHtmlFixedPositionTest() (err error) {
	defer catch(&err)

	// Convert PDF document to HTML with fixed positioning option turned on (default)
	fmt.Println("Converting PDF to HTML with fixed positioning option turned on (default)")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_fixed_positioning"

	// Convert to HTML
	ConvertToHtml(inputFile, outputFile)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToHtmlReflowParagraphTest1() (err error) {
	defer catch(&err)

	// Convert PDF document to HTML with reflow full option turned on (1)
	fmt.Println("Converting PDF to HTML with reflow full option turned on (1)")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_reflow_full.html"

	htmlOutputOptions := NewHTMLOutputOptions()

	// Set e_reflow_full content reflow setting
	htmlOutputOptions.SetContentReflowSetting(HTMLOutputOptionsE_reflow_full);

	// Convert to HTML
	ConvertToHtml(inputFile, outputFile, htmlOutputOptions)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToHtmlReflowParagraphTest2() (err error) {
	defer catch(&err)

	// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
	fmt.Println("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_reflow_full_first_page.html"

	htmlOutputOptions := NewHTMLOutputOptions()

	// Set e_reflow_full content reflow setting
	htmlOutputOptions.SetContentReflowSetting(HTMLOutputOptionsE_reflow_full);

	// Convert only the first page
	htmlOutputOptions.SetPages(1, 1);

	// Convert to HTML
	ConvertToHtml(inputFile, outputFile, htmlOutputOptions)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func main() {
    // The first step in every application using PDFNet is to initialize the 
    // library. The library is usually initialized only once, but calling 
    // Initialize() multiple times is also fine.
    PDFNetInitialize(PDFTronLicense.Key)

	//-----------------------------------------------------------------------------------

	// Convert PDF document to HTML with fixed positioning option turned on (default)
	err := ConvertToHtmlFixedPositionTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to HTML, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	PDFNetAddResourceSearchPath("../../../PDFNetC/Lib/")

	if !StructuredOutputModuleIsModuleAvailable() {
		fmt.Println("")
		fmt.Println("Unable to run part of the sample: PDFTron SDK Structured Output module not available.")
		fmt.Println("-------------------------------------------------------------------------------------")
		fmt.Println("The Structured Output module is an optional add-on, available for download")
		fmt.Println("at https://docs.apryse.com/core/guides/info/modules . If you have already")
		fmt.Println("downloaded this module, ensure that the SDK is able to find the required file")
		fmt.Println("using the PDFNet::AddResourceSearchPath() function.")
		fmt.Println("")
		return
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to HTML with reflow full option turned on (1)
	err = ConvertToHtmlReflowParagraphTest1()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to HTML, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
	err = ConvertToHtmlReflowParagraphTest2()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to HTML, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

    PDFNetTerminate()
    fmt.Println("Done.")
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to HTML.
//
// There are two HTML modules and one of them is an optional PDFNet Add-on.
// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
//    documents.
// 2. The optional add-on module is used to convert PDF documents to HTML documents with
//    text flowing across the browser window.
//
// The Apryse SDK HTML add-on module can be downloaded from http://www.pdftron.com/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

public class PDF2HtmlTest 
{
    // Relative path to the folder containing test files.
    static String inputPath = "../../TestFiles/";
    static String outputPath = "../../TestFiles/Output/";

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    public static void main(String[] args) 
    {
        // The first step in every application using PDFNet is to initialize the 
        // library. The library is usually initialized only once, but calling 
        // Initialize() multiple times is also fine.
        PDFNet.initialize(PDFTronLicense.Key());

        boolean err = false;

        //////////////////////////////////////////////////////////////////////////
        
        try {
            // Convert PDF document to HTML with fixed positioning option turned on (default)
            System.out.println("Converting PDF to HTML with fixed positioning option turned on (default)");

            String outputFile = outputPath + "paragraphs_and_tables_fixed_positioning";

            Convert.toHtml(inputPath + "paragraphs_and_tables.pdf", outputFile);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to HTML, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////
        
        PDFNet.addResourceSearchPath("../../../Lib/");

        try {
            if (!StructuredOutputModule.isModuleAvailable()) {
                System.out.println();
                System.out.println("Unable to run part of the sample: Apryse SDK Structured Output module not available.");
                System.out.println("-------------------------------------------------------------------------------------");
                System.out.println("The Structured Output module is an optional add-on, available for download");
                System.out.println("at https://docs.apryse.com/core/guides/info/modules . If you have already");
                System.out.println("downloaded this module, ensure that the SDK is able to find the required files");
                System.out.println("using the PDFNet::AddResourceSearchPath() function.");
                System.out.println();
                return;
            }
        } catch (PDFNetException e) {
            System.out.println(e);
            return;
        }  catch (Exception e) {
            System.out.println(e);
            return;
        }

        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to HTML with reflow full option turned on (1)
            System.out.println("Converting PDF to HTML with reflow full option turned on (1)");

            String outputFile = outputPath + "paragraphs_and_tables_reflow_full.html";

            Convert.HTMLOutputOptions htmlOutputOptions = new Convert.HTMLOutputOptions();

            // Set e_reflow_full content reflow setting
            htmlOutputOptions.setContentReflowSetting(Convert.HTMLOutputOptions.e_reflow_full);

            Convert.toHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to HTML, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////
        
        try {
            // Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
            System.out.println("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)");

            String outputFile = outputPath + "paragraphs_and_tables_reflow_full_first_page.html";

            Convert.HTMLOutputOptions htmlOutputOptions = new Convert.HTMLOutputOptions();

            // Set e_reflow_full content reflow setting
            htmlOutputOptions.setContentReflowSetting(Convert.HTMLOutputOptions.e_reflow_full);

            // Convert only the first page
            htmlOutputOptions.setPages(1, 1);

            Convert.toHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to HTML, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////

        PDFNet.terminate();
        System.out.println("Done.");        
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to HTML.
//
// There are two HTML modules and one of them is an optional PDFNet Add-on.
// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
//    documents.
// 2. The optional Structured Output add-on module is used to convert PDF documents to
//    HTML documents with text flowing across the browser window.
//
// The Apryse SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
	'use strict';

	exports.runPDF2HtmlTest = () => {

		const main = async () => {

			const inputPath = '../TestFiles/';
			const outputPath = '../TestFiles/Output/';

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to HTML with fixed positioning option turned on (default)
				console.log('Converting PDF to HTML with fixed positioning option turned on (default)');

				const outputFile = outputPath + 'paragraphs_and_tables_fixed_positioning';

				// Convert PDF to HTML
				await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			await PDFNet.addResourceSearchPath('../../lib/');

			if (!await PDFNet.StructuredOutputModule.isModuleAvailable()) {
				console.log('\nUnable to run part of the sample: Apryse SDK Structured Output module not available.');
				console.log('---------------------------------------------------------------');
				console.log('The Structured Output module is an optional add-on, available for download');
				console.log('at https://docs.apryse.com/core/guides/info/modules . If you have already');
				console.log('downloaded this module, ensure that the SDK is able to find the required files');
				console.log('using the PDFNet::AddResourceSearchPath() function.\n');

				return;
			}

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to HTML with reflow full option turned on (1)
				console.log('Converting PDF to HTML with reflow full option turned on (1)');

				const outputFile = outputPath + 'paragraphs_and_tables_reflow_full.html';

				const htmlOutputOptions = new PDFNet.Convert.HTMLOutputOptions();

				// Set e_reflow_full content reflow setting
				htmlOutputOptions.setContentReflowSetting(PDFNet.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);

				// Convert PDF to HTML
				await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile, htmlOutputOptions);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
				console.log('Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)');

				const outputFile = outputPath + 'paragraphs_and_tables_reflow_full_first_page.html';

				const htmlOutputOptions = new PDFNet.Convert.HTMLOutputOptions();

				// Set e_reflow_full content reflow setting
				htmlOutputOptions.setContentReflowSetting(PDFNet.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);

				// Convert only the first page
				htmlOutputOptions.setPages(1, 1);

				// Convert PDF to HTML
				await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile, htmlOutputOptions);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			console.log('Done.');
		};

		PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
			console.log('Error: ' + JSON.stringify(error));
		}).then(function () { return PDFNet.shutdown(); });
	};
	exports.runPDF2HtmlTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=PDF2HtmlTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to HTML.
//
// There are two HTML modules and one of them is an optional PDFNet Add-on.
// 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
//    documents.
// 2. The optional add-on module is used to convert PDF documents to HTML documents with
//    text flowing across the browser window.
//
// The PDFTron SDK HTML add-on module can be downloaded from https://dev.apryse.com/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

function main()
{
	// Relative path to the folder containing the test files.
	$inputPath = getcwd()."/../../TestFiles/";
	$outputPath = $inputPath."Output/";

	// The first step in every application using PDFNet is to initialize the 
	// library. The library is usually initialized only once, but calling 
	// Initialize() multiple times is also fine.
	global $LicenseKey;
	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
	
	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to HTML with fixed positioning option turned on (default)
		echo(nl2br("Converting PDF to HTML with fixed positioning option turned on (default)\n"));

		$outputFile = $outputPath."paragraphs_and_tables_fixed_positioning";

		Convert::ToHtml($inputPath."paragraphs_and_tables.pdf", $outputFile);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to HTML, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	PDFNet::AddResourceSearchPath("../../../PDFNetC/Lib/");

	if (!StructuredOutputModule::IsModuleAvailable()) {
		echo(nl2br("\n"));
		echo(nl2br("Unable to run part of the sample: PDFTron SDK Structured Output module not available.\n"));
		echo(nl2br("-------------------------------------------------------------------------------------\n"));
		echo(nl2br("The Structured Output module is an optional add-on, available for download\n"));
		echo(nl2br("at https://docs.apryse.com/core/guides/info/modules . If you have already\n"));
		echo(nl2br("downloaded this module, ensure that the SDK is able to find the required files\n"));
		echo(nl2br("using the PDFNet::AddResourceSearchPath() function.\n"));
		echo(nl2br("\n"));
		return;
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to HTML with reflow full option turned on (1)
		echo(nl2br("Converting PDF to HTML with reflow full option turned on (1)\n"));

		$outputFile = $outputPath."paragraphs_and_tables_reflow_full.html";

		$htmlOutputOptions = new HTMLOutputOptions();

		// Set e_reflow_full content reflow setting
		$htmlOutputOptions->SetContentReflowSetting(HTMLOutputOptions::e_reflow_full);

		Convert::ToHtml($inputPath."paragraphs_and_tables.pdf", $outputFile, $htmlOutputOptions);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to HTML, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
		echo(nl2br("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)\n"));

		$outputFile = $outputPath."paragraphs_and_tables_reflow_full_first_page.html";

		$htmlOutputOptions = new HTMLOutputOptions();

		// Set e_reflow_full content reflow setting
		$htmlOutputOptions->SetContentReflowSetting(HTMLOutputOptions::e_reflow_full);

		// Convert only the first page
		$htmlOutputOptions->SetPages(1, 1);

		Convert::ToHtml($inputPath."paragraphs_and_tables.pdf", $outputFile, $htmlOutputOptions);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to HTML, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------
	PDFNet::Terminate();
	echo(nl2br("Done.\n"));
}

main();
?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

import platform

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class to convert 
# documents and files to HTML.
#
# There are two HTML modules and one of them is an optional PDFNet Add-on.
# 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
#    documents.
# 2. The optional add-on module is used to convert PDF documents to HTML documents with
#    text flowing across the browser window.
#
# The PDFTron SDK HTML add-on module can be downloaded from https://dev.apryse.com/
#
# Please contact us if you have any questions.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
inputPath = "../../TestFiles/"
outputPath = "../../TestFiles/Output/"

def main():
    # The first step in every application using PDFNet is to initialize the 
    # library. The library is usually initialized only once, but calling 
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)
    
    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to HTML with fixed positioning option turned on (default)
        print("Converting PDF to HTML with fixed positioning option turned on (default)")

        outputFile = outputPath + "paragraphs_and_tables_fixed_positioning"

        Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to HTML, error: " + str(e))

    #-----------------------------------------------------------------------------------

    PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")

    if not StructuredOutputModule.IsModuleAvailable():
        print("")
        print("Unable to run part of the sample: PDFTron SDK Structured Output module not available.")
        print("-------------------------------------------------------------------------------------")
        print("The Structured Output module is an optional add-on, available for download")
        print("at https://docs.apryse.com/core/guides/info/modules . If you have already")
        print("downloaded this module, ensure that the SDK is able to find the required files")
        print("using the PDFNet::AddResourceSearchPath() function.")
        print("")
        return

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to HTML with reflow full option turned on (1)
        print("Converting PDF to HTML with reflow full option turned on (1)")

        outputFile = outputPath + "paragraphs_and_tables_reflow_full.html"

        htmlOutputOptions = HTMLOutputOptions()

        # Set e_reflow_full content reflow setting
        htmlOutputOptions.SetContentReflowSetting(HTMLOutputOptions.e_reflow_full)

        Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to HTML, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
        print("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)")

        outputFile = outputPath + "paragraphs_and_tables_reflow_full_first_page.html"

        htmlOutputOptions = HTMLOutputOptions()

        # Set e_reflow_full content reflow setting
        htmlOutputOptions.SetContentReflowSetting(HTMLOutputOptions.e_reflow_full)

        # Convert only the first page
        htmlOutputOptions.SetPages(1, 1)

        Convert.ToHtml(inputPath + "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to HTML, error: " + str(e))

    #-----------------------------------------------------------------------------------

    PDFNet.Terminate()
    print("Done.")
    
if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class to convert 
# documents and files to HTML.
#
# There are two HTML modules and one of them is an optional PDFNet Add-on.
# 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
#    documents.
# 2. The optional add-on module is used to convert PDF documents to HTML documents with
#    text flowing across the browser window.
#
# The PDFTron SDK HTML add-on module can be downloaded from https://dev.apryse.com/
#
# Please contact us if you have any questions.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
$inputPath = "../../TestFiles/"
$outputPath = "../../TestFiles/Output/"
	
def main()
	# The first step in every application using PDFNet is to initialize the 
	# library. The library is usually initialized only once, but calling 
	# Initialize() multiple times is also fine.
	PDFNet.Initialize(PDFTronLicense.Key)

	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to HTML with fixed positioning option turned on (default)
		puts "Converting PDF to HTML with fixed positioning option turned on (default)"

		$outputFile = $outputPath + "paragraphs_and_tables_fixed_positioning"

		Convert.ToHtml($inputPath + "paragraphs_and_tables.pdf", $outputFile)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to HTML, error: " + error.message
	end

	#-----------------------------------------------------------------------------------

	PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");

	if !StructuredOutputModule.IsModuleAvailable() then
		puts ""
		puts "Unable to run part of the sample: PDFTron SDK Structured Output module not available."
		puts "-------------------------------------------------------------------------------------"
		puts "The Structured Output module is an optional add-on, available for download"
		puts "at https://docs.apryse.com/core/guides/info/modules . If you have already"
		puts "downloaded this module, ensure that the SDK is able to find the required files"
		puts "using the PDFNet::AddResourceSearchPath() function."
		puts ""
		return
	end

	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to HTML with reflow full option turned on (1)
		puts "Converting PDF to HTML with reflow full option turned on (1)"

		$outputFile = $outputPath + "paragraphs_and_tables_reflow_full.html"

		$htmlOutputOptions = Convert::HTMLOutputOptions.new()

		# Set e_reflow_full content reflow setting
		$htmlOutputOptions.SetContentReflowSetting(Convert::HTMLOutputOptions::E_reflow_full)

		Convert.ToHtml($inputPath + "paragraphs_and_tables.pdf", $outputFile, $htmlOutputOptions)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to HTML, error: " + error.message
	end

	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
		puts "Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)"

		$outputFile = $outputPath + "paragraphs_and_tables_reflow_full_first_page.html"

		$htmlOutputOptions = Convert::HTMLOutputOptions.new()

		# Set e_reflow_full content reflow setting
		$htmlOutputOptions.SetContentReflowSetting(Convert::HTMLOutputOptions::E_reflow_full)

		# Convert only the first page
		$htmlOutputOptions.SetPages(1, 1)

		Convert.ToHtml($inputPath + "paragraphs_and_tables.pdf", $outputFile, $htmlOutputOptions)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to HTML, error: " + error.message
	end

	#-----------------------------------------------------------------------------------
	PDFNet.Terminate
	puts "Done."
end

main()
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
'

Imports System
Imports pdftron
Imports pdftron.Common
Imports pdftron.PDF

' The following sample illustrates how to use the PDF:Convert utility Class To convert 
' documents And files to HTML.
'
' There are two HTML modules And one of them Is an optional PDFNet Add-on.
' 1. The built-in HTML module Is used to convert PDF documents to fixed-position HTML
'    documents.
' 2. The optional add-on module Is used to convert PDF documents to HTML documents with
'    text flowing across the browser window.
'
' The Apryse SDK HTML add-on module can be downloaded from http://www.pdftron.com/
'
' Please contact us if you have any questions.	
'
' Also note that conversion under ASP.NET can be tricky to configure. Please see the following document for advice: 
' http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf

Module PDF2HtmlTestVB
    Class Class1
        Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()

        Shared Sub New()
        End Sub

        ' Relative path to the folder containing test files.
        Const inputPath As String = "../../../../TestFiles/"
        Const outputPath As String = "../../../../TestFiles/Output/"

        <STAThread>
        Shared Sub Main(ByVal args As String())
            ' The first step in every application using PDFNet Is to initialize the 
            ' library. The library Is usually initialized only once, but calling 
            ' Initialize() multiple times Is also fine.
            PDFNet.Initialize(PDFTronLicense.Key)

            Dim err As Boolean = False

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to HTML with fixed positioning option turned on (default)
                Console.WriteLine("Converting PDF to HTML with fixed positioning option turned on (default)")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_fixed_positioning.html"

                pdftron.PDF.Convert.ToHtml(inputPath & "paragraphs_and_tables.pdf", outputFile)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to HTML, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            PDFNet.AddResourceSearchPath("../../../../../Lib/")

            If Not StructuredOutputModule.IsModuleAvailable() Then
                Console.WriteLine()
                Console.WriteLine("Unable to run part of the sample: Apryse SDK Structured Output module not available.")
                Console.WriteLine("-------------------------------------------------------------------------------------")
                Console.WriteLine("The Structured Output module is an optional add-on, available for download")
                Console.WriteLine("at http://docs.apryse.com/core/guides/info/modules . If you have already downloaded this")
                Console.WriteLine("module, ensure that the SDK is able to find the required files")
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
                Console.WriteLine()
                Return
            End If

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to HTML with reflow full option turned on (1)
                Console.WriteLine("Converting PDF to HTML with reflow full option turned on (1)")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_reflow_full.html"

                Dim htmlOutputOptions As pdftron.PDF.Convert.HTMLOutputOptions = New pdftron.PDF.Convert.HTMLOutputOptions()

                ' Set e_reflow_full content reflow setting
                htmlOutputOptions.SetContentReflowSetting(pdftron.PDF.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full)

                pdftron.PDF.Convert.ToHtml(inputPath & "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to HTML, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
                Console.WriteLine("Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_reflow_full_first_page.html"

                Dim htmlOutputOptions As pdftron.PDF.Convert.HTMLOutputOptions = New pdftron.PDF.Convert.HTMLOutputOptions()

                ' Set e_reflow_full content reflow setting
                htmlOutputOptions.SetContentReflowSetting(pdftron.PDF.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full)

                ' Convert only the first page
                htmlOutputOptions.SetPages(1, 1)

                pdftron.PDF.Convert.ToHtml(inputPath & "paragraphs_and_tables.pdf", outputFile, htmlOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to HTML, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            PDFNet.Terminate()
            Console.WriteLine("Done.")
        End Sub
    End Class
End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/pdf2htmltest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
