
Auto Convert PDFs to HTML and Publish to Web
3 MIN READ
PDF.co can convert searchable and scanned PDF documents into HTML while preserving document elements such as text, fonts, images, vectors, tables, and page formatting.
In this tutorial, you will:
The current PDF to HTML endpoint is:
POST /v1/pdf/convert/to/html
For the complete parameter reference, see the PDF.co PDF to HTML API documentation.
Before starting, prepare:
You can also use the PDF.co API Tester to run the request from your browser.
PDF.co must be able to access the source document.
You can use:
filetoken:// reference from PDF.co FilesA browser preview page or a link requiring an interactive login may not work. The URL should point directly to the source document.
This tutorial uses the following PDF.co sample file:
https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf
Sign in to your PDF.co account and obtain your API key.
For command-line testing, store it in an environment variable.
On macOS or Linux:
export PDFCO_API_KEY="YOUR_API_KEY"In Windows PowerShell:
$env:PDFCO_API_KEY="YOUR_API_KEY"Replace YOUR_API_KEY with your actual PDF.co API key.
Do not place production API keys in public repositories or client-side application code.
Send a POST request to:
https://api.pdf.co/v1/pdf/convert/to/html
A basic JSON request body looks like this:
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf",
"pages": "0-",
"lang": "eng",
"inline": false,
"async": false,
"name": "result.html",
"password": "",
"profiles": ""
}0- processes the entire document.Use the following command to convert the sample PDF:
curl --request POST \
--url 'https://api.pdf.co/v1/pdf/convert/to/html' \
--header 'Content-Type: application/json' \
--header "x-api-key: $PDFCO_API_KEY" \
--data '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf",
"pages": "0-",
"lang": "eng",
"inline": false,
"async": false,
"name": "result.html",
"password": "",
"profiles": ""
}'PDF.co will process the document and return a JSON response.
A successful response resembles the following:
{
"url": "https://pdf-temp-files.s3.amazonaws.com/example/index.html",
"pageCount": 1,
"error": false,
"status": 200,
"name": "result.html",
"credits": 10,
"remainingCredits": 990
}Important response properties include:
Confirm that error is false before using the output URL.
Open the URL returned in the response to view the converted document in a browser.
To download the HTML from the command line, copy the returned URL and run:
curl --location 'PDFCO_OUTPUT_URL' --output result.htmlReplace PDFCO_OUTPUT_URL with the complete URL returned by PDF.co.
PDF.co output URLs use temporary storage. Download the result or transfer it to permanent storage before the link expires.
If the generated HTML references related image or asset files, preserve those dependencies when moving the output to another hosting environment.
You have converted a PDF into HTML using the current PDF.co API.
The same workflow can be incorporated into websites, document-management systems, automation platforms, and server-side applications.
Create an account, get an API key and test a request.