Extract text and tables from a PDF
pdf_extract_textExtract page-by-page text and tables from born-digital PDFs in reading order, with optional line positions; scanned PDFs without a text layer are listed but not OCR'd.
Instructions
Read the text of a born-digital PDF (one made by software: invoices, statements, reports, contracts, forms), page by page, in reading order, plus any tables found from the text layout as rows of cells. Scanned PDFs (images of pages) have no text layer and come back listed in pages_without_text: OCR is not supported. Set include_lines to also get each line with its position in PDF points from the bottom-left of the page as the viewer sees it, the same frame pdf_edit uses, so you can stamp text next to something you found. Up to 200 pages per call; pass pages to read a large document in parts. To search for specific text instead, use pdf_find_text. With tables_format xlsx the tables come back as one Excel workbook instead (one sheet per table, all cells text): written to output_path (a .xlsx file) when given, otherwise returned inline as an application/vnd.openxmlformats-officedocument.spreadsheetml.sheet resource (a workbook over 7 MB is never returned inline: pass output_path). The source PDF is never modified; output_path is only written with tables_format xlsx.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"pdf_path": "<pdf_path>"
},
"name": "pdf_extract_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pages | No | Pages to read, 1-based: "1-3,5,8-". Default: all pages. | |
| password | No | Password to open the input, only needed for a user-password PDF (owner-locked files with an empty user password open without it). | |
| pdf_path | Yes | PDF source: a path to a .pdf file inside the allowed directories (PDFOPS_ROOT, default the working directory), an https:// URL, or a data:application/pdf;base64,… URI. Use a URL or data URI when this server runs remotely (Smithery, hosted gateways) where local paths do not exist. | |
| output_path | No | Only with tables_format xlsx: path of a .xlsx file to write the workbook to, inside the allowed directories (PDFOPS_ROOT, default the working directory); an existing file there is overwritten. Omit when running remotely: the workbook is then returned inline as a resource for the client to save. | |
| include_lines | No | Also return every line of text with x, y, width and font size in points. Default false (smaller output). | |
| tables_format | No | csv adds a csv string (RFC 4180, CRLF line ends) to each table next to rows. xlsx instead returns one Excel workbook, one sheet per table ("Page 3 Table 1"), with a short summary (no text, lines or rows); every cell is a text string, never a formula, and numbers are not converted. xlsx fails with no_tables when the pages read have no table (if the read stopped early the error says so and names the pages value to continue with). Default json. In csv cell values are returned verbatim: a cell starting with = + - or @ can run as a formula if the CSV is opened in a spreadsheet, so sanitise before opening. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bytes | No | Only with tables_format=xlsx: size of the workbook | |
| pages | No | ||
| truncated | No | ||
| page_count | No | Pages in the document | |
| output_path | No | Only with tables_format=xlsx: absolute path written, when output_path was supplied | |
| resource_uri | No | Only with tables_format=xlsx: where the workbook resource is attached, when output_path was omitted | |
| truncated_by | No | Only with tables_format=xlsx and truncated: which cap stopped the read or cut the workbook | |
| cells_truncated | No | Only with tables_format=xlsx: a cell over 32,767 characters was cut | |
| pages_without_text | No |