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
| Input | A PDF: upload, raw body, or url (up to 25 MB) |
|---|---|
| Output | One HTML document, in JSON or as an HTML file |
| Layouts | fixed (looks like the PDF) or flow (semantic and reflowable) |
| Pages per request | Up to 100 (fixed) or 5 (flow) |
| Plan usage | 1 document page (fixed) or 1 AI page (flow) per page |
| Free plan | PDFs up to 2 MB, 3 pages (fixed) or 2 (flow) per request |
Related APIs
- PDF to Image API - PDF pages to JPG, PNG or WebP images
- PDF to JPG API - PDF pages to JPG images
- PDF to PNG API - PDF pages to lossless PNG images
- Image to PDF API - JPG, PNG and other images to one PDF
- JPG to PDF API - JPG photos and scans to one PDF
- PNG to PDF API - PNG screenshots and charts to one PDF
- Word to PDF API - Word documents (.docx or .doc) to PDF
- HTML to PDF API - HTML, templates and web pages to PDF
- Image to Text API - Read the text in an image (OCR)
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.
fileoptionalThe PDF, as a multipart form upload, up to about 4 MB (2 MB on the Free plan).
urloptionalA public
http://orhttps://link to a PDF, up to 25 MB, instead of an upload. Works with GET or POST.layoutoptionalfixed(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.pagesoptionalThe pages to convert: one page (
3) or a range (2-5, or4-for page 4 onwards). Default: from page 1. Each request converts up to 100 pages infixedlayout and 5 inflow; when the PDF has more,next_pagein the response says where to continue.passwordoptionalThe password of a password-protected PDF.
backgroundoptionalfixedlayout: format of the page backgrounds (images, shapes and lines behind the text):png(default),jpg(smaller files for photo-heavy pages) orsvg(sharp at any zoom, best for drawings and charts; some images with transparency, such as icons, can come out as solid shapes, so usepngif they look wrong).dpioptionalfixedlayout: resolution of the page background images, from72to300. Default144.widthoptionalfixedlayout: scale every page to this width in pixels, from320to4000. Default: the PDF's own page size.imagesoptionalflowlayout: include the PDF's figures and photos as embedded images:true(default) orfalsefor text only.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Acceptoptionaltext/htmlreturns the HTML itself instead of JSON, with the page numbers in theX-Page-Count,X-Total-PagesandX-Next-Pageresponse headers.Content-Typeoptionalapplication/pdfwhen 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).
layoutThe layout used: fixed or flow.
page_countNumber of pages converted in this response.
first_pageThe first page converted.
total_pagesNumber of pages in the PDF.
next_pageThe 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.
sizeSize of the HTML in bytes.
htmlThe HTML, one self-contained document: fonts, styles and images are embedded, so it opens offline. Scripts are never included.
html_urlPaid plans: for HTML larger than about 4 MB, a link to download it instead of html. The link works for one hour.
expires_atWhen 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
fixedlayout and 5 inflow; continue fromnext_pagefor longer PDFs. - Uploads up to about 4 MB; PDFs from
urlup 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:
fixedlayout shows them as images, andflowlayout returns them as figures. - In
flowlayout, 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
flowlayout, 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
fixedlayout or 2 inflow.
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
Press Send to convert the sample invoice PDF and preview the HTML here.
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.htmlErrors
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.
| Cause | Example error |
|---|---|
| No PDF in the request | Send the PDF as file (a multipart form upload), as the request body, or as url. |
| The file is not a PDF | The file is not a PDF. |
A password-protected PDF without password | The PDF is password-protected. Send its password. |
A wrong password | The password is not correct. |
An unknown layout | layout must be fixed or flow. |
A pages value that is not a page or range | pages must be one page (3) or a range (2-5 or 4-). |
pages outside the PDF, e.g. pages=5 for a 3-page PDF | The PDF has only 3 pages. |
| A range longer than one request converts | layout=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=flow | dpi applies to layout=fixed. |
A PDF at url over 25 MB | The PDF is larger than 25 MB. |
| The pages take too long to convert | The PDF took too long to convert. Convert fewer pages per request with pages. |
| No AI pages left this month | You 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 MB | PDFs 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 limit | The 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
Can I use the PDF to HTML API for commercial purposes?
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.How do I get an API key and start using the PDF to HTML API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
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.What happens if a request to the PDF to HTML API fails?
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.How do I convert a PDF to HTML with an API?
POST the PDF to/v1/pdftohtmlas a multipart upload namedfile, 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 theAcceptheader the response is JSON with the HTML inhtmland the page numbers. A PDF that is already online can be passed asurl, or sent as the raw body withContent-Type: application/pdf.Which layout should I choose: fixed or flow?
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.flowrebuilds 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.fixeduses document pages;flow, which runs AI layout analysis, uses AI pages.Is the text in the HTML real text?
Yes, in both layouts: text stays selectable, searchable and copyable, not pictures of text. Scanned pages have no text to read, sofixedlayout shows them as images andflowlayout returns them as figures. To read the text in a scan, use the Image to Text API.How do I convert a long PDF?
Each request converts up to 100 pages infixedlayout and 5 inflowlayout. When a PDF has more, the response'snext_pagesays where to continue: send the next request withpages=<next_page>-untilnext_pageisnull.total_pagesgives the length of the PDF up front.How much of my plan does PDF to HTML use?
No API calls. Each page converted uses one page of your plan's monthly allowance: a document page infixedlayout (Free 50, Developer 10,000, Business 100,000, Professional 500,000) or an AI page inflowlayout (Free 10, Developer 1,000, Business 10,000, Professional 50,000). Your dashboard shows the pages you've used this month. See pricing.Can I convert PDF to HTML on the Free plan?
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 infixedlayout or 2 inflow. Paid plans convert PDFs up to 25 MB, 100 or 5 pages per request. See pricing.
Explore API integration use cases for recommended APIs and workflow examples.