# ⚡PDF to HTML Converter - Fast & Responsive (`microtrica/pdf-to-html`) Actor

⚡Effortlessly transform ➡️ your PDF documents 📑 into responsive, mobile-friendly 🌐HTML pages. Boost web performance with perfect conversions and seamless browser compatibility.

- **URL**: https://apify.com/microtrica/pdf-to-html.md
- **Developed by:** [Microtrica](https://apify.com/microtrica) (community)
- **Categories:** Developer tools
- **Stats:** 10 total users, 0 monthly users, 100.0% runs succeeded, 2 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## 📑 PDF to HTML Converter

This actor converts PDF documents into responsive HTML pages using the [`pdf2htmlEX`](https://github.com/pdf2htmlEX/pdf2htmlEX) tool. It leverages modern web technologies to ensure precise rendering of text, images, fonts, and layouts. Whether you're looking to convert a simple document or a complex magazine layout, this tool delivers optimized HTML output for web use.

**💵 Pricing Models**

This actor operates on a **monthly rental** pricing model. You can start with a free trial, and once it ends, a monthly subscription will be required to continue using the tool.

If you'd prefer a pay-per-result option (paying per PDF conversion), please visit [this link](https://apify.com/microtrica/pdf-to-html-lite).

### 🔧 How It Works

1. **Input the PDF**: Upload the PDF you want to convert.

2. **Convert to HTML**: The actor uses `pdf2htmlEX` to process the PDF and produce an HTML file.

3. **Download HTML Output**: After conversion, the resulting HTML file is available for download.

### 🎯 Key Features

- **Single HTML Output**: Converts the entire PDF into one HTML file.
- **Optimized Rendering**: Maintains the integrity of fonts, images, and text for accurate web display.
- **Zoom and DPI Control**: Adjust zoom levels and specify DPI for images for enhanced clarity.
- **Interactive and Printable HTML**: Generate interactive content like forms, and enable or disable printing.
- **Math and Formula Support**: Renders scientific papers with complex mathematical equations.

#### 🖼 Demo

A beautiful demo is worth a thousand words. Explore some example conversions below:

- **[Typography Example](https://pdf2htmlex.github.io/pdf2htmlEX/demo/geneve.html)** — [Geneve 1564 PDF](https://github.com/raphink/geneve_1564/releases/download/2016-06-08_02/geneve_1564.pdf) ([Author](https://github.com/raphink/geneve_1564))

- **[Formulas Example](https://pdf2htmlex.github.io/pdf2htmlEX/demo/cheat.html)** — [Formulas PDF](http://www.tug.org/texshowcase/cheat.pdf) ([Author](http://www.tug.org/texshowcase))

- **[Magazine Example](https://pdf2htmlex.github.io/pdf2htmlEX/demo/issue65_en.html)** — [Full Circle Magazine PDF](http://dl.fullcirclemagazine.org/issue65_en.pdf) ([Author](http://fullcirclemagazine.org))

- **[Scientific Paper](https://pdf2htmlex.github.io/pdf2htmlEX/demo/demo.html)** — [Scientific PDF](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.148.349\&rep=rep1\&type=pdf) ([Author](https://citeseerx.ist.psu.edu))

### 📂 Output

The output HTML file will be saved in the Apify key-value store, and a link to the file will be added to the dataset.

### 📝 Limitations

- **Type 3 Fonts**: Not supported yet (rendered as images instead).

- **Non-text Objects**: Non-text elements are rendered as images.

- **PDF Standard Compliance**: Files that don’t follow the PDF standard may not convert properly.

- **Library Dependencies**: Conversion may fail due to limitations in the underlying libraries (Poppler, FontForge).

### ⚠️ Troubleshooting

If the actor doesn't work for your PDF:

- **Bug Reports**: File an issue with a link to the problematic PDF file.

- **Known Issues**: See [pdf2htmlEX Limitations](https://github.com/pdf2htmlEX/pdf2htmlEX/wiki/Limitations).

### ⚖️ License and Credits

This actor is powered by the [pdf2htmlEX project](https://github.com/pdf2htmlEX/pdf2htmlEX), originally developed by [**Lu Wang (coolwanglu)**](https://github.com/coolwanglu). Special thanks to the authors of the [pdf2htmlEX fork](https://github.com/pdf2htmlEX/pdf2htmlEX).

pdf2htmlEX is licensed under the [GPLv2 & GPLv3 Dual License](https://github.com/pdf2htmlEX/pdf2htmlEX/blob/master/LICENSE_GPLv3). Many thanks are due to all contributors for making this tool available.

### ⚠️ Troubleshooting & Contact

See [pdf2htmlEX Limitations](https://github.com/pdf2htmlEX/pdf2htmlEX/wiki/Limitations).
If the actor doesn't work for your PDF, or if you have any feedback, feature requests, or encounter bugs, feel free to file an issue in the Apify console or reach out via support.

# Actor input Schema

## `startUrls` (type: `array`):

Provide the URLs to the PDF files you wish to convert.

## `maxRequestsPerCrawl` (type: `integer`):

Maximum number of requests that can be made by the crawler.

## `f` (type: `integer`):

Specify the first page to process. If not provided, the default is 1.

## `l` (type: `integer`):

Specify the last page to process. If not provided, the entire document will be processed.

## `zoom` (type: `string`):

Specify the zoom factor. By default, the pages will be rendered at 72DPI if not specified.

## `fitWidth` (type: `integer`):

Maximum width of the page (in pixels).

## `fitHeight` (type: `integer`):

Maximum height of the page (in pixels).

## `dpi` (type: `integer`):

Set the DPI for the conversion process. Default is 144.

## `useCropbox` (type: `boolean`):

Use CropBox instead of MediaBox for output (default: true).

## `processNonText` (type: `boolean`):

Process non-text elements (like images) during the conversion (default: true).

## `processOutline` (type: `boolean`):

Whether to include the PDF's outline in the generated HTML (default: true).

## `printing` (type: `boolean`):

Enable support for printing. Disabling it may reduce CSS size (default: true).

## `fallback` (type: `boolean`):

Enable fallback mode for better accuracy and browser compatibility (default: false). This option may increase the file size.

## `embedExternalFont` (type: `boolean`):

Embed fonts that are not embedded in the original PDF (default: true).

## `fontFormat` (type: `string`):

Choose the format for extracted fonts from the PDF (default: woff).

## `heps` (type: `integer`):

Specify the maximum horizontal offset in pixels (default: 1).

## `veps` (type: `integer`):

Specify the maximum vertical offset in pixels (default: 1).

## `spaceThreshold` (type: `string`):

Insert a space between letters when the distance exceeds the specified threshold (default: 0.125).

## `fontSizeMultiplier` (type: `string`):

Adjust the font size multiplier to improve rendering accuracy (default: 4.0).

## `spaceAsOffset` (type: `boolean`):

Treat spaces as offsets for better optimization (default: false).

## `tounicode` (type: `string`):

Specify how to apply the ToUnicode map (-1 for custom, 0 for balance, 1 for always). Default is 0.

## `optimizeText` (type: `boolean`):

Reduce the number of HTML elements used for text (default: false).

## `bgFormat` (type: `string`):

Specify the background image format (default: png).

## `ownerPassword` (type: `string`):

Specify the owner password for the PDF, if protected.

## `userPassword` (type: `string`):

Specify the user password for the PDF, if protected.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://apify.com/ext/ycf_application.pdf"
    }
  ],
  "maxRequestsPerCrawl": 3,
  "f": 1,
  "l": 10,
  "zoom": "1.5",
  "fitWidth": 1024,
  "fitHeight": 768,
  "dpi": 144,
  "useCropbox": true,
  "processNonText": true,
  "processOutline": true,
  "printing": true,
  "embedExternalFont": true,
  "fontFormat": "woff",
  "heps": 2,
  "veps": 2,
  "spaceThreshold": "0.2",
  "fontSizeMultiplier": "3.5",
  "spaceAsOffset": false,
  "tounicode": "1",
  "optimizeText": false,
  "bgFormat": "png"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        {
            "url": "https://apify.com/ext/ycf_application.pdf"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("microtrica/pdf-to-html").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "startUrls": [{ "url": "https://apify.com/ext/ycf_application.pdf" }] }

# Run the Actor and wait for it to finish
run = client.actor("microtrica/pdf-to-html").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://apify.com/ext/ycf_application.pdf"
    }
  ]
}' |
apify call microtrica/pdf-to-html --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,microtrica/pdf-to-html"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/WicdAcmQlnI0lPJWN/builds/4OeYPoM2JtEhBC0WM/openapi.json
