Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to convert PDF to HTML (Tutorial)

4 min read

PDF forms to HTML forms using Java (Icon)

PDF to HTML using Java (Icon)

In this article I will show you how you can use our PDF files to HTML API to convert documents to HTML with our library BuildVu. PDF to HTML conversion helps you to optimise your PDF content for display on browsers. We have a separate article explaining the benefits of converting PDF to HTML.

Convert PDF to HTML using Java

  1. Download the BuildVu trial jar
  2. Add the BuildVu Jar to your project libraries
  3. Choose conversion options
  4. Choose viewer options
  5. Set PDF file path and output directory

 

Convert PDF to HTML from the command line

You can run the BuildVu API to convert directly from the command line which is useful for using the converter with another language or script.

  1. Download the BuildVu trial jar
  2. Set the input directory and output directory
  3. Choose conversion options
  4. Increase the XMX value according to need


The default mode generates the document inside the IDRViewer. To generate just the raw content to be used inside your own custom solution, you can use:

 

You can also convert PDF to HTML in a lot of other languages using a hosted BuildVu Cloud API using:

Convert PDF to HTML using Ruby

While you can access these services using standard HTTP requests, this tutorial utilizes our open-source Ruby IDRCloudClient, which offers a straightforward Ruby wrapper for the REST API.

Prerequisites

There are two ways to integrate the IDRCloudClient into your project.

Using the gem: Install the idr_cloud_client gem with the following command:


Alternatively, add the line “gem ‘idr_cloud_client'” to your application’s Gemfile and then run the following command:

You can check out documentation for BuildVu to learn more on how to turn PDF into an HTML. If you want to convert PDF to SVG you can check out our other article here.

Code Example

Below is a simple code example to convert PDF files to HTML or SVG. Additional configuration options and advanced features are detailed below:

Return result to a callback url

The BuildVu Microservice supports a callback URL to notify you of the conversion status upon completion. This eliminates the need to continuously check the service for updates. You can provide the callback URL to the convert method as demonstrated below:

Configuration Options

The BuildVu API allows customization of your conversion using a stringified JSON object with key-value pair configuration options. Provide these settings to the convert method. A comprehensive list of configuration options for converting PDF files to HTML or SVG is available here.

Upload by URL

In addition to uploading a local file, you can provide a URL that the BuildVu Microservice will download and convert. To do this, replace the input and file values in the convert method with the following.

Using Authentication

If you’ve set up your own BuildVu Microservice that needs a username and password for converting PDF files to HTML, you must provide these credentials with each conversion. You can do this by passing a variable named auth to the convert method as demonstrated below.

 

Convert PDF to HTML using Python

This tutorial uses our Python IDRCloudClient open source which provides a simple Python wrapper around the REST API.

Prerequisites

Using pip, install the IDRCloudClient package with the following command:

Code Examples

Below is a basic code example for converting PDF files to HTML or SVG. Additional configuration options and advanced features are detailed below.

Return result to a callback url

The BuildVu Microservice supports a callback URL to send the status of a conversion on completion. Using a callback URL eliminates the need to continually check the service for updates. You can provide the callback URL to the `convert` method as shown below:

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pair configuration options. Provide these settings to the convert method. A comprehensive list of options for converting PDF files to HTML or SVG is available here.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Simply replace the input and file values in the convert method with the following.

Using Authentication

For deployments of your own BuildVu Microservice that require a username and password for PDF-to-HTML or SVG conversions, provide these credentials with each conversion. Pass a variable named auth to the convert method as demonstrated below.

 

Convert PDF to HTML using PHP

Although the services can be accessed with standard HTTP requests, this tutorial uses our open-source PHP IDRCloudClient, which offers a straightforward PHP wrapper for the REST API.

Prerequisites

To install the idrsolutions-php-client package using Composer, execute the following command:

Code Examples

This is a basic code example to convert PDF files to HTML or SVG. Configuration options and advanced features are detailed below:

Return result to a callback url

The BuildVu Microservice supports a callback URL to send the status upon conversion completion, eliminating the need to constantly poll the service. You can provide the callback URL to the parameters array as demonstrated below:

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pair configuration options. Add these settings to the parameters array. A comprehensive list of options for converting PDF files to HTML or SVG can be found here.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Simply replace the input and file values in the parameters array with the following.

Using Authentication

If you’ve deployed your own BuildVu Microservice that requires a username and password for converting PDF files to HTML or SVG, you’ll need to provide these credentials for each conversion. Add two variables named username and password to the parameters array, as shown below.

In such cases, you’ll also need to provide the authentication values to the downloadOutput method.

 

Convert PDF to HTML using NodeJS

To install the idrcloudclient package using npm, run the following command:


Create an idrcloudclient object with:

Create endpoint variable

Create Parameters map to upload a file

[Optional] Create listeners to trigger on progress, success, and failure.



Call convert method using variables created previously

Return result to a callback url

The BuildVu Microservice supports a callback URL to notify you upon conversion status completion. Using a callback URL eliminates the need to constantly poll the service.

You can provide the callback URL to the parameters variable as demonstrated below:

Complete Code Example

Here is a complete code example for converting PDF files to HTML or SVG, following the steps outlined in the previous sections. Configuration options and advanced features can be found in the sections that follow:

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pair configuration options. Add these settings to the parameters array. A comprehensive list of options for converting PDF files to HTML or SVG is available here.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Replace the input and file values in the parameters variable with the following.

Using Authentication

If you’ve deployed your own BuildVu Microservice that requires a username and password for converting PDF files to HTML or SVG, you will need to provide these credentials for each conversion. Add two variables named username and password to the convert method as shown below.

 

Convert PDF to HTML using JavaScript

This tutorial uses our open source Javascript IDRCloudClient which provides a simple Javascript wrapper around the REST API.

Prerequisites

To incorporate the client into your project, add the idrcloudclient.js file to your project and include the following line to access it:

<script src="path/to/idrcloudclient.js" type="text/javascript"></script>

Code Examples

Here is a simple code example for converting PDF files to HTML or SVG. Detailed configuration options and advanced features are provided below:

You can find an example using the JavaScript client here.

Return result to a callback url

The BuildVu Microservice supports a callback URL to notify you of the status of a conversion upon completion. Using a callback URL eliminates the need to constantly poll the service.

You can provide the callback URL to the parameters variable as demonstrated below:

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pairs. These settings should be added to the parameters array. A complete list of configuration options for converting PDF files to HTML or SVG can be found here.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Replace the input and file values in the parameters variable with the following:

Using Authentication

If you have deployed your own BuildVu Microservice that requires a username and password to convert PDF files to HTML or SVG, you must provide these credentials for each conversion. Pass two variables named username and password to the convert method as shown below.

 

Convert PDF to HTML using cURL

Although the aforementioned services can be accessed using cURL with the REST API.

Prerequisites

Before you begin, ensure that cURL is installed. Setup instructions vary based on your operating system; more details can be found on the cURL website.

Code Examples

Here is a simple code example for converting PDF files to HTML or SVG. Please note that the file entry must be prefixed with ‘@’, followed by the file path (absolute or relative).

Detailed configuration options and advanced features are provided below:

The response will contain a uuid and will be in Jason format.

You can use this to poll the progress of your conversion and obtain the URL for the output once the conversion is complete.

The response will be in JSON format and will include the following details:

You can use the previewURL to view the output in your browser.

Additionally, you can download the converted output using the download URL with the following cURL request.

Return result to a callback url

The BuildVu Microservice supports a callback URL to notify of the status of conversion completion. Using a callback URL eliminates the need to poll the service to determine when the conversion is finished.

The callback URL can be provided as shown below:

Configuration Options

The BuildVu API allows you to customize your conversion by accepting a stringified JSON object with key-value pairs for configuration options. These settings should be added before the URL in the cURL command. You can find a complete list of configuration options for converting PDF files to HTML or SVG here.

Note that the syntax for escaping double quotes can vary depending on the environment you use, make sure to check what works for your specific environment:

Note that for PowerShell your command should start with curl.exe –% to avoid parsing errors.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Simply replace the input and file values with the following.

Using Authentication

If you’ve deployed your own BuildVu Microservice that requires a username and password for converting PDF files to HTML or SVG, you need to provide these credentials for each conversion. Add the user flag with the username and password before the URL.

 

Convert PDF to HTML using C#

Although the aforementioned services can be accessed using plain HTTP requests, this tutorial utilizes our open-source C# IDRCloudClient, which offers a straightforward C# wrapper around the REST API.

Prerequisites

To install the idrsolutions-csharp-client package using NuGet, run the following command:

Code Example

Here is a basic code example for converting PDF files to HTML or SVG. Detailed configuration options and advanced features are provided below.

Return result to a callback url

The BuildVu Microservice supports a callback URL to notify you on the status of conversion completion. Using a callback URL eliminates the need to poll the service to check when the conversion is complete.

The callback URL can be provided to the convert method as demonstrated below:

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pairs. These settings should be added to the parameters array. A comprehensive list of configuration options for converting PDF files to HTML or SVG is available here.

Upload by URL

In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. Replace the input and file values in the parameters variable with the following settings.

Using Authentication

If you’ve deployed your own BuildVu Microservice that requires a username and password for converting PDF files to HTML or SVG, you must provide these credentials for each conversion. Pass two variables named username and password to the convert

 

Convert PDF to HTML using Dart

This tutorial our REST API.

Prerequisites

Before you start, ensure that you have the latest version of the Dart SDK installed. For more information, visit the Dart website. Additionally, you should install the following libraries:

Code Examples

Here is a basic code example for converting PDF files to HTML or SVG. Detailed configuration options and advanced features can be found below:

Return result to a callback url

The BuildVu Microservice supports a callback URL to send the conversion status upon completion. Using a callback URL eliminates the need to poll the service to check when the conversion is complete. The callback URL can be provided to the params map as shown below.

Configuration Options

The BuildVu API allows for conversion customization using a stringified JSON object with key-value pairs. These settings should be added to the parameters array. A comprehensive list of configuration options for converting PDF files to HTML or SVG can be found here.

Upload by URL

In addition to uploading a local file, you can provide a URL that the BuildVu Microservice will download and convert. Replace the input and file values in the parameters variable with the following configuration.

Using Authentication

If the BuildVu Microservice requires authentication, you need to provide a username and password. Pass these credentials by including two variables named `username` and `password` in the `convert` method as shown below.

We have other articles aimed at helping you with all things PDF, you can find them here.



BuildVu allows you to

View PDF files in a Web app
Convert PDF documents to HTML5
Parse PDF documents as HTML
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.