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. BuildVu is the best PDF to HTML conversion tool for developers. 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 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:
composer require idrsolutions/idrsolutions-php-client
Code Examples
Here is a basic code example demonstrating how to generate HTML from PDF. Configuration options and advanced features are detailed below:
‘input’ => IDRCloudClient::INPUT_UPLOAD,
‘file’ => __DIR__ . ‘path/to/file.pdf’
);
$results = IDRCloudClient::convert(array(
‘endpoint’ => $endpoint,
‘parameters’ => $parameters
));
IDRCloudClient::downloadOutput($results, __DIR__ . ‘/’);
echo $results[‘downloadUrl’];
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:
$parameters = array(
//’token’ => ‘Token’, // Required only when connecting to the IDRsolutions trial and cloud subscription service
‘input’ => IDRCloudClient::INPUT_UPLOAD,
‘callbackUrl’ => ‘http://listener.url’,
‘file’ => __DIR__ . ‘path/to/file.pdf’
);
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.
‘settings’ => ‘{"key":"value","key":"value"}’
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.
‘input’ => IDRCloudClient.DOWNLOAD
‘url’ => ‘http://exampleURL/exampleFile.pdf’
Using Authentication
If you require authentication for your BuildVu Microservice, provide username and password when converting and downloading HTML from PDF. Add two variables named username and password to the parameters array, as shown below.
‘username’ => ‘Username_If_Required’,
‘password’ => ‘Password_If_Required’,
In such cases, you’ll also need to provide the authentication values to the downloadOutput method.
IDRCloudClient::downloadOutput($results, __DIR__ . ‘/’,’newFileName’,’username’,’password’);
BuildVu allows you to
View PDF files in a Web app |
Convert PDF documents to HTML5 |
Parse PDF documents as HTML |
What is BuildVu?
BuildVu is a commercial SDK for converting PDF files into standalone HTML or SVG.
Why use BuildVu?
BuildVu allows you to integrate PDF into your HTML workflow effortlessly and securely by producing clean HTML that is easy for developers to work with.
What licenses are available?
We have 3 licenses available:
Cloud for conversion using the shared IDRsolutions cloud server, Self hosted server option for your own cloud or on-premise servers, and Enterprise for more demanding requirements.
How to use BuildVu?
Want to learn more about BuildVu and how to use it, we have plenty of tutorials and guides to help you.