Overview
Extraction runs on unpdf, a serverless build of Mozilla's pdf.js. For each page the text items are joined in the order pdf.js reports them: an item that ends a line adds a line break, and otherwise a space is added unless the item already ends in whitespace. Runs of spaces are collapsed, spaces before a line break are removed and the page text is trimmed. This is the content order stored in the file, which for most documents is reading order but can interleave columns in some layouts.
Send the file as a multipart upload or base64 in `pdf`, or a public URL in `pdf` or `url`. A link without a scheme gets https:// added, GitHub `/blob/` links, Google Drive `/file/d/` links and Dropbox `?dl=0` links are rewritten to their direct-download form, and a URL that returns a web page instead of a PDF gets a 400 saying so. The file must carry a `%PDF-` header in its first kilobyte. Files over 10 MB return 413, a password-protected PDF returns 400 asking for the password to be removed, and a file pdf.js cannot open returns 400.
Only the first 100 pages are read. `pageCount` is the full count from the file, `pagesExtracted` the number read, and `truncated` is true when they differ. `text` joins the pages with a blank line and is trimmed; `characterCount` is its length and `wordCount` sums each page's count of whitespace-separated tokens. `hasText` is false when the joined text is empty, which is what a scanned PDF with no text layer produces.
On paid plans `pages` holds `{page, text, wordCount}` for each page read, and `metadata` comes from the PDF's information dictionary, with null for any missing entry. PDF dates such as `D:20240115103000+01'00'` are converted to ISO 8601 in UTC, and `pdfVersion` is the format version, such as 1.7. On the Free plan `pages` and `metadata` are null.
Endpoint
One host, one path per API. The block below shows this call in four languages; every one of them is the same HTTP request. Making requests covers the timeouts, retries and parameter rules that apply to all of them. The SDKs wrap the same call in a typed client.
curl -X POST https://api.apiverve.com/v1/pdftotext \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/basicapi.pdf"
}'const res = await fetch('https://api.apiverve.com/v1/pdftotext', {
method: 'POST',
headers: {
'x-api-key': 'your_api_key_here',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/basicapi.pdf"
}),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();
console.log(data);import requests
res = requests.post(
"https://api.apiverve.com/v1/pdftotext",
headers={"x-api-key": "your_api_key_here"},
json={
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/basicapi.pdf"
},
timeout=15,
)
res.raise_for_status()
print(res.json()["data"])package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader(`{
"pdf": "https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/basicapi.pdf"
}`)
req, _ := http.NewRequest("POST", "https://api.apiverve.com/v1/pdftotext", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your_api_key_here")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}Replace your_api_key_here with the key from your dashboard. When the inputs arrive as a list rather than one at a time, batch requests run up to 200 of them through this same API in a single call.
Authentication
Send your key in the x-api-key header. That is the only auth step — there is no token exchange and no per-endpoint scope to configure. Authentication covers creating, rotating and revoking keys.
A 401 means the key is missing, invalid or expired. A 403 means the key is valid but not permitted here — blocked by a key restriction or an IP allow-list. Running out of credits is a 429.
Parameters
Sent as JSON in the request body. Premium parameters are accepted on every plan but only take effect on plans that include them.
| Parameter | Type | Description |
|---|---|---|
pdfOptional | string | The PDF file to read (up to 10 MB), or a public PDF URL. GitHub, Google Drive and Dropbox share links are turned into their direct download, and a missing https:// is added |
Response
Every API returns the same three top-level keys, so one response handler covers your whole integration: status, error and data. Only data changes shape. Response format covers the envelope, the other output formats and how premium fields are withheld.
{
"status": "ok",
"error": null,
"data": {
"text": "Table Of Content\nChapter 1 .......................................................... 2\nParagraph 1.1 ...................................................... 3\npage 1 / 3\n\nChapter 1\npage 2 / 3\n\nParagra…",
"pageCount": 3,
"pagesExtracted": 3,
"truncated": false,
"hasText": true,
"wordCount": 31,
"characterCount": 250,
"pages": [
{
"page": 1,
"text": "Table Of Content\nChapter 1 .......................................................... 2\nParagraph 1.1 ...................................................... 3\npage 1 / 3",
"wordCount": 15
},
{
"page": 2,
"text": "Chapter 1\npage 2 / 3",
"wordCount": 6
},
{
"page": 3,
"text": "Paragraph 1.1\nPowered by TCPDF (www.tcpdf.org)\npage 3 / 3",
"wordCount": 10
}
],
"metadata": {
"title": "Basic API Test",
"author": "Brendan Dahl",
"subject": null,
"creator": "pdf.js",
"producer": "TCPDF 5.9.133 (http://www.tcpdf.org)",
"creationDate": "2012-04-10T21:30:26.000Z",
"modificationDate": "2012-04-10T21:30:26.000Z",
"pdfVersion": "1.7"
}
}
}
Response fields
Paths are relative to data. Premium fields are absent rather than zeroed on plans that do not include them, so check for presence instead of comparing to 0.
| Field | Type | Example | Description |
|---|---|---|---|
text | string | "Table Of Content
Chapter 1 .......................................................... 2
Paragraph 1.…" | The extracted text, pages separated by a blank line |
pageCount | number | 3 | Total pages in the PDF |
pagesExtracted | number | 3 | Pages read (at most 100) |
truncated | boolean | false | True when the PDF has more pages than were read |
hasText | boolean | true | False when no text layer was found, as in a scanned PDF |
wordCount | number | 31 | Words in the extracted text |
characterCount | number | 250 | Characters in the extracted text |
pagesPremium | array[3] | The text of each page read | |
pagePremium | number | 1 | Page number |
textPremium | string | "Table Of Content
Chapter 1 .......................................................... 2
Paragraph 1.…" | Text of the page |
wordCountPremium | number | 15 | Words on the page |
metadataPremium | object | {...} | Document information from the PDF |
titlePremium | string | "Basic API Test" | Document title, or null |
authorPremium | string | "Brendan Dahl" | Author, or null |
subjectPremium | object | null | Subject, or null |
creatorPremium | string | "pdf.js" | Application that created the original document, or null |
producerPremium | string | "TCPDF 5.9.133 (http://www.tcpdf.org)" | Application that produced the PDF, or null |
creationDatePremium | string | "2012-04-10T21:30:26.000Z" | Creation date (ISO 8601), or null |
modificationDatePremium | string | "2012-04-10T21:30:26.000Z" | Last modification date (ISO 8601), or null |
pdfVersionPremium | string | "1.7" | PDF format version, such as 1.7 |
Errors
Read the HTTP status first, then error for the specific reason. The body names the parameter that has to change. Error handling covers the full status list and which of them are worth retrying.
| Status | Meaning | What to do |
|---|---|---|
400 | Input was rejected | Read error; it names the parameter. |
401 | Key missing or invalid | Check the header name and the key value. |
403 | Key valid, but not permitted | A key restriction or IP allow-list; see key scoping. |
429 | Rate limited, or out of credits | Read error to tell them apart; see rate limits. |
Use cases
- Search Indexing
- Index the text of uploaded PDFs so users can search inside documents, not just their titles.
- AI and RAG Pipelines
- Feed PDF text, page by page, into embeddings or a language model for question answering over documents.
- Document Intake
- Read invoices, statements and forms as text for downstream parsing and validation.
- Content Moderation
- Check the text of uploaded PDFs against your policies before they are published.
Other ways to use PDF to Text
Set up PDF to Text on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them — one key, one balance.
Related
More in Documents: