PDF to Text API
Extract the text layer of a PDF page by page (Vietnamese Unicode kept), with document metadata, word counts and a warning for scanned files.
The PDF text API reads the text layer of a PDF with the PDF.js engine and returns it page by page (pages: [{ page, text }]) or as one string with merge=true. Vietnamese text produced by Word, LibreOffice, invoicing software or our own PDF APIs is returned as proper Unicode. pages=2-4 restricts the output to some pages.
The answer also contains the document information (title, author, creator, producer), the total page count and character and word counts. When pages have no text at all, a note warns that the file looks scanned: such PDFs are images and need OCR, which this API does not do.
Up to 500 pages are read per call by default (max_pages, at most 2,000), within the file size of your plan. Password-protected PDFs are refused. Layout (columns, tables) is flattened to lines of text.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
file | body | file | yes | The PDF (multipart, raw body or file_base64). | |
pages | query|body | string | no | Pages to return, e.g. 1-3,5. | |
merge | query|body | boolean | no | false | true: one text string instead of pages. |
max_pages | query|body | number | no | 500 | Refuse longer documents unless pages is given (1–2000). |
Example
curl -X POST "https://apibox.io.vn/v1/pdf-text" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "0=@./my-file"const form = new FormData();
form.append('0', fileInput.files[0]);
const res = await fetch('https://apibox.io.vn/v1/pdf-text', {
method: 'POST',
headers: { Authorization: 'Bearer YOUR_API_KEY' },
body: form,
});
console.log(await res.json());import requests
res = requests.post(
"https://apibox.io.vn/v1/pdf-text",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"0": open("my-file", "rb")},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/pdf-text');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
CURLOPT_POSTFIELDS => ['0' => new CURLFile('my-file')],
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"pages_total": 1,
"pages_returned": 1,
"info": {
"title": "Báo giá",
"author": null,
"creator": "apibox.io.vn",
"producer": "APIBox md-pdf"
},
"characters": 137,
"words": 32,
"pages": [
{
"page": 1,
"text": "Báo giá dịch vụ\nKính gửi Quý khách,\nCông ty xin gửi báo giá gói API Pro: 15 USD / tháng.\nĐiều khoản\nThanh toán trong 7 ngày.\n1 / 1Báo giá"
}
]
}
Use cases
- Index uploaded PDF documents for search
- Read amounts and references from PDF invoices
- Feed contracts and reports to an AI pipeline
- Check that a generated PDF contains the expected text
FAQ
Does it work on scanned documents?
No. A scanned PDF only contains images; the API detects it and says so in note. OCR is needed for those files.
Is the table layout kept?
No, the text comes line by line in reading order. Tables become lines with their cell values.
What is the page limit?
500 pages by default, up to 2,000 with max_pages, and the file size of your plan.
Related APIs
Image Metadata & EXIF
Read image dimensions, format, EXIF camera data, capture settings and GPS location from JPEG, PNG, WebP, HEIC, AVIF, GIF and more – upload or URL.
PDFPDF Metadata
Read PDF metadata: page count, title, author, creator, producer, dates, PDF version, encryption, form fields and the size of each page (A4, Letter…).
PDF₫Quote & Receipt PDF
Generate clean PDF quotations, receipts, orders and simple invoices from JSON, with Vietnamese text, VAT, totals in words and a VietQR code for payment.