NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server →

PDF to HTML API

The PDF to HTML API converts PDF files to HTML, in one of two layouts. Upload a PDF or send a link, and get back one self-contained HTML document with its fonts, styles and images embedded, ready to show in a browser, store or index.

The default fixed layout keeps every page looking exactly like the PDF, with real, selectable and searchable text instead of images of text. Use it to show PDFs on a website or in an app without a PDF viewer.

The flow layout uses AI layout analysis to rebuild the document as clean, semantic HTML: headings, paragraphs, lists, tables and figures that reflow on any screen. Use it to make PDFs readable on phones, to import them into a CMS, to index them for search, or to give their content to AI models.

Each page converted uses one page of your plan's monthly allowance, not API calls: a document page in the default fixed layout (Free 50, Developer 10,000, Business 100,000, Professional 500,000), or an AI page in the flow layout (Free 10, Developer 1,000, Business 10,000, Professional 50,000). Your dashboard shows the pages you've used this month. See pricing.

Need the other direction? The HTML to PDF API turns HTML and web pages into PDFs. The PDF to Image API turns PDF pages into images, each with its text.

At a Glance

InputA PDF: upload, raw body, or url (up to 25 MB)
OutputOne HTML document, in JSON or as an HTML file
Layoutsfixed (looks like the PDF) or flow (semantic and reflowable)
Pages per requestUp to 100 (fixed) or 5 (flow)
Plan usage1 document page (fixed) or 1 AI page (flow) per page
Free planPDFs up to 2 MB, 3 pages (fixed) or 2 (flow) per request

Related APIs

https://api.api-ninjas.com/v1/pdftohtml

Converts a PDF to HTML, in a fixed layout that looks like the PDF or a flow layout that reflows. Returns the HTML in JSON, or as an HTML file. Accepts GET or POST: use POST to upload the PDF, or GET with url.

Parameters

Send the PDF in one of three ways: as file (a multipart form upload), as url, or as the raw request body with Content-Type: application/pdf. The other parameters can be query parameters or multipart form fields.

  • file  optional

    The PDF, as a multipart form upload, up to about 4 MB (2 MB on the Free plan).

  • url  optional

    A public http:// or https:// link to a PDF, up to 25 MB, instead of an upload. Works with GET or POST.

  • layout  optional

    fixed (default): every page looks exactly like the PDF, with real, selectable text and the fonts and images embedded. flow: clean, semantic HTML (headings, paragraphs, lists, tables and figures) that reflows on any screen, for reading, search, CMS import and AI models.

  • pages  optional

    The pages to convert: one page (3) or a range (2-5, or 4- for page 4 onwards). Default: from page 1. Each request converts up to 100 pages in fixed layout and 5 in flow; when the PDF has more, next_page in the response says where to continue.

  • password  optional

    The password of a password-protected PDF.

  • background  optional

    fixed layout: format of the page backgrounds (images, shapes and lines behind the text): png (default), jpg (smaller files for photo-heavy pages) or svg (sharp at any zoom, best for drawings and charts; some images with transparency, such as icons, can come out as solid shapes, so use png if they look wrong).

  • dpi  optional

    fixed layout: resolution of the page background images, from 72 to 300. Default 144.

  • width  optional

    fixed layout: scale every page to this width in pixels, from 320 to 4000. Default: the PDF's own page size.

  • images  optional

    flow layout: include the PDF's figures and photos as embedded images: true (default) or false for text only.

Headers

  • X-Api-Key  required

    API Key associated with your account.

  • Accept  optional

    text/html returns the HTML itself instead of JSON, with the page numbers in the X-Page-Count, X-Total-Pages and X-Next-Page response headers.

  • Content-Type  optional

    application/pdf when the request body is the PDF itself. Multipart uploads set their own content type.

Response

The /v1/pdftohtml endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful (see errors).

  • layout

    The layout used: fixed or flow.

  • page_count

    Number of pages converted in this response.

  • first_page

    The first page converted.

  • total_pages

    Number of pages in the PDF.

  • next_page

    The next page to convert, when the PDF has more pages than this response; send it as pages (for example pages=6-) to continue. null when the last page has been converted.

  • size

    Size of the HTML in bytes.

  • html

    The HTML, one self-contained document: fonts, styles and images are embedded, so it opens offline. Scripts are never included.

  • html_url

    Paid plans: for HTML larger than about 4 MB, a link to download it instead of html. The link works for one hour.

  • expires_at

    When html_url stops working (UTC, ISO 8601).

With Accept: text/html, the response body is the HTML document (Content-Type: text/html; charset=utf-8), or for HTML larger than about 4 MB, a redirect (HTTP 303) to its download link.

Limits

  • Up to 100 pages per request in fixed layout and 5 in flow; continue from next_page for longer PDFs.
  • Uploads up to about 4 MB; PDFs from url up to 25 MB.
  • HTML up to about 4 MB comes back in the response; larger HTML, up to 100 MB, as a download link that works for one hour.
  • Scanned pages have no text to read: fixed layout shows them as images, and flow layout returns them as figures.
  • In flow layout, page numbers are left out, and a header or footer that repeats on every page, such as a report's running title, is kept once.
  • In flow layout, the reading order of complex pages, such as text in several columns around figures, can differ from the PDF.
  • Free plan: PDFs up to 2 MB, and up to 3 pages per request in fixed layout or 2 in flow.

Document pages and AI pages

This API uses your plan's monthly page allowances, not API calls. Each page converted in fixed layout uses one document page; each page converted in flow layout, which runs AI layout analysis, uses one AI page. If you have fewer pages left than you asked for, the response converts the pages left, and next_page points at the rest.

Live Demo

Live demo · no API key required
Form data and query parameters
file
Converts this sample invoice PDF until you choose a file.
layout
pages

Get a free API key to get started — no credit card required.

Headers
X-Api-KeyLog in or sign up to get your API key
POST
https://api.api-ninjas.com/v1/pdftohtml
Sample response

Press Send to convert the sample invoice PDF and preview the HTML here.

{
"layout": "fixed",
"page_count": 1,
"first_page": 1,
"total_pages": 1,
"next_page": null,
"size": 392580,
"html": "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\"/>..."
}

The live demo converts the first page, from PDFs up to 2 MB. No API key is needed to try it.

Code Examples

# Convert a PDF to HTML that looks like the original curl -X POST "https://api.api-ninjas.com/v1/pdftohtml" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Accept: text/html" \ -F "file=@report.pdf" \ --output report.html # Clean, reflowable HTML of pages 1 to 5 curl -X POST "https://api.api-ninjas.com/v1/pdftohtml?layout=flow&pages=1-5" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Accept: text/html" \ -F "file=@report.pdf" \ --output report-flow.html

Errors

An invalid request returns HTTP 400 with a JSON body holding a readable error message. If too many PDFs are being converted at once, the API returns HTTP 503: retry after a few seconds. Authentication and quota errors use the standard format described in error codes.

CauseExample error
No PDF in the requestSend the PDF as file (a multipart form upload), as the request body, or as url.
The file is not a PDFThe file is not a PDF.
A password-protected PDF without passwordThe PDF is password-protected. Send its password.
A wrong passwordThe password is not correct.
An unknown layoutlayout must be fixed or flow.
A pages value that is not a page or rangepages must be one page (3) or a range (2-5 or 4-).
pages outside the PDF, e.g. pages=5 for a 3-page PDFThe PDF has only 3 pages.
A range longer than one request convertslayout=flow converts up to 5 pages per request. Send the next range with pages.
An option for the other layout, e.g. dpi with layout=flowdpi applies to layout=fixed.
A PDF at url over 25 MBThe PDF is larger than 25 MB.
The pages take too long to convertThe PDF took too long to convert. Convert fewer pages per request with pages.
No AI pages left this monthYou have used all 10 AI pages included in your Free plan this month. They renew on December 1, 2026. Upgrade at https://api-ninjas.com/pricing for more.
Free plan: a PDF over 2 MBPDFs on the Free plan can be up to 2 MB. Upgrade at https://api-ninjas.com/pricing for files up to 25 MB.
Free plan: a range over the per-request limitThe Free plan converts up to 2 pages per request with layout=flow. Upgrade at https://api-ninjas.com/pricing for up to 5.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the PDF to HTML API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • POST the PDF to /v1/pdftohtml as a multipart upload named file, e.g. curl -X POST "https://api.api-ninjas.com/v1/pdftohtml" -H "X-Api-Key: YOUR_API_KEY" -H "Accept: text/html" -F "file=@report.pdf" --output report.html. Without the Accept header the response is JSON with the HTML in html and the page numbers. A PDF that is already online can be passed as url, or sent as the raw body with Content-Type: application/pdf.
  • fixed (the default) keeps every page looking exactly like the PDF, with selectable text: choose it to show PDFs on a website without a PDF viewer. flow rebuilds the document as semantic HTML (headings, paragraphs, lists, tables and figures) that reflows on any screen: choose it for reading on phones, importing into a CMS, search indexing or sending the content to AI models. fixed uses document pages; flow, which runs AI layout analysis, uses AI pages.
  • Yes, in both layouts: text stays selectable, searchable and copyable, not pictures of text. Scanned pages have no text to read, so fixed layout shows them as images and flow layout returns them as figures. To read the text in a scan, use the Image to Text API.
  • Each request converts up to 100 pages in fixed layout and 5 in flow layout. When a PDF has more, the response's next_page says where to continue: send the next request with pages=<next_page>- until next_page is null. total_pages gives the length of the PDF up front.
  • No API calls. Each page converted uses one page of your plan's monthly allowance: a document page in fixed layout (Free 50, Developer 10,000, Business 100,000, Professional 500,000) or an AI page in flow layout (Free 10, Developer 1,000, Business 10,000, Professional 50,000). Your dashboard shows the pages you've used this month. See pricing.
  • Yes: the Free plan includes 50 document pages and 10 AI pages a month, for PDFs up to 2 MB, converting up to 3 pages per request in fixed layout or 2 in flow. Paid plans convert PDFs up to 25 MB, 100 or 5 pages per request. See pricing.