How to Convert PDF to HTML Using the PDF.co API

6 Minutes 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:

  1. Prepare a source PDF.
  2. Send it to the PDF.co PDF to HTML endpoint.
  3. Review the API response.
  4. Open or download the generated HTML.
  5. Adjust advanced conversion and OCR options when necessary.

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.

What You Will Need

Before starting, prepare:

  • A PDF.co account
  • A PDF.co API key
  • A PDF available through a direct URL
  • A tool capable of making HTTP requests, such as cURL, Postman, or an application in your preferred programming language

You can also use the PDF.co API Tester to run the request from your browser.

Step 1: Prepare the Source PDF

PDF.co must be able to access the source document.

You can use:

  • A publicly accessible HTTPS URL
  • A temporary upload URL generated through PDF.co
  • A filetoken:// reference from PDF.co Files

A 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

Step 2: Configure the API Key

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.

Step 3: Create the PDF-to-HTML Request

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": ""
}

Parameter Details

  • url: Direct URL or PDF.co file reference for the source document.
  • pages: Zero-based pages to process. 0- processes the entire document.
  • lang: OCR language used for scanned pages.
  • inline: When false, PDF.co returns a temporary URL for the generated HTML.
  • async: When false, the request waits for processing to finish.
  • name: Desired output filename.
  • password: Password for a protected source PDF.
  • profiles: Optional advanced conversion settings.

Step 4: Run the Request with cURL

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.

Step 5: Review the 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:

  • url: Temporary URL of the generated HTML.
  • pageCount: Number of pages processed.
  • error: Indicates whether PDF.co reported an error.
  • status: PDF.co processing status.
  • name: Generated output filename.
  • credits: Credits consumed by the operation.
  • remainingCredits: Credits remaining in the account.
  • outputLinkValidTill: Expiration time, when included.

Confirm that error is false before using the output URL.

Step 6: Open or Download the HTML

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.html

Replace 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.

Conclusion

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.

Get Your API Key
Explore API Docs

Related Tutorials

See Related Tutorials