pdf parser python

PDF Parsing for Python

One endpoint. POST a PDF, get complete Markdown back — simple tables as GFM, and complex table structure preserved as sanitized HTML when GFM would be lossy.

Server-side PDF processing. Review privacy, security, and data retention.

Process a selected folder

The bounded local-file batch recipe saves input snapshots and one identity per PDF before submission. It processes up to five files sequentially, writes complete Markdown without overwriting files and stops for explicit recovery on uncertain results. Continue with the table extraction workflow when your output contains tables.

Choose a Python workflow by input and output

Use the validated Python examples for URL, Base64 or raw PDF requests. They set a timeout, require saved account identities, validate canonical success and write only Markdown.

Select local or hosted processing

PyMuPDF supports integrated OCR through Tesseract, and PyMuPDF4LLM supports Markdown workflows. pdfplumber supports line, text and explicit table strategies. Camelot uses pdfium by default; Ghostscript is optional. These setup choices are not absent capabilities. Current sources and comparison, checked 10 September 2026.

Use a virtual environment

Install requests in an isolated environment. Read the API key from the environment and keep it out of code and logs. Save the request identity before submitting account work.

Handle errors before parsing content

Require HTTP 200 and the complete typed response before accessing Markdown. Pending work, quota errors and timeouts must not become empty successful output. Recover uncertain account work with identical bytes, options and identity.

Convert a document

Use the tested Python, JavaScript or curl workflow. Choose one input: a public PDF URL, Base64 bytes, or a raw PDF upload. Raw uploads avoid Base64 expansion; all three send the document to an external processor.

See the API reference for authentication, limits and recovery.

Optional API demo: invoice PDF to Markdown

Bash, curl and Python 3. This demo script validates success before printing Markdown.

#!/usr/bin/env bash
set -euo pipefail
key=demo_public_key
identity=demo-example
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
result=$work/result
status=$(curl --silent --show-error --max-time 660 -o "$result" -w '%{http_code}' \
  "https://pdftomarkdown.dev/v1/convert" \
  -H "Authorization: Bearer $key" -H "Idempotency-Key: $identity" \
  -H "Content-Type: application/json" \
  --data '{"input":{"pdf_url":"https://pdftomarkdown.dev/samples/invoice.pdf"}}')
if [ "$status" != 200 ]; then echo "HTTP $status; keep the identity for recovery" >&2; exit 1; fi
python3 - "$result" <<'PY'
import json, sys
with open(sys.argv[1]) as response:
    result = json.load(response)
if not (isinstance(result, dict) and result.get("complete") is True
        and isinstance(result.get("markdown"), str)
        and type(result.get("pages")) is int and result["pages"] >= 0
        and isinstance(result.get("request_id"), str) and result["request_id"].strip()):
    sys.exit("Incomplete or invalid conversion response")
sys.stdout.write(result["markdown"])
PY
{
  "complete": true,
  "markdown": "# CONTOSO LTD.\n\n# INVOICE\n\nContoso Headquarters\n\n123 456th St\n\nNew York, NY, 10001\n\nINVOICE: INV-100\n\nDATE: 11/15/2019\n\nDUE DATE: 12/15/2019\n\nCUSTOMER NAME: MICROSOFT CORPORATION\n\nCUSTOMER ID: CID-12345\n\nMicrosoft Corp\n\n123 Other St,\n\nRedmond WA, 98052\n\nBILL TO:\n\nMicrosoft Finance\n\n123 Bill St,\n\nRedmond WA, 98052\n\nSHIP TO:\n\nMicrosoft Delivery\n\n123 Ship St,\n\nRedmond WA, 98052\n\nSERVICE ADDRESS:\n\nMicrosoft Services\n\n123 Service St,\n\nRedmond WA, 98052\n\n| SALESPERSON | P.O. NUMBER | REQUISITIONER | SHIPPED VIA | F.O.B. POINT | TERMS |\n| --- | --- | --- | --- | --- | --- |\n|  | PO-3333 |  |  |  |  |\n\n<table><tr><th>QUANTITY</th><th>DESCRIPTION</th><th>UNIT PRICE</th><th>TOTAL</th></tr><tr><td>1</td><td>Test for 23 fields</td><td>1</td><td>$100.00</td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td colspan=\"3\">SUBTOTAL</td><td>$100.00</td></tr><tr><td colspan=\"3\">SALES TAX</td><td>$10.00</td></tr><tr><td colspan=\"3\">TOTAL</td><td>$110.00</td></tr><tr><td colspan=\"3\">PREVIOUS BALANCE</td><td>$500.00</td></tr><tr><td colspan=\"3\">TOTAL DUE</td><td>$610.00</td></tr></table>\n\nTHANK YOU FOR YOUR BUSINESS!\n\nREMIT TO:\n\nContoso Billing\n\n123 Remit St\n\nNew York, NY, 10001\n\n> Processed by pdfToMarkdown.dev",
  "pages": 1,
  "request_id": "req_example_invoice"
}

Pricing

Try page 1 free, or get 20 trial pages once with a new account. Then choose paid credits. Monthly pages expire; top-ups do not.