Skip to main content

pdflite

pdflite turns a PDF into markdown that a person or a language model can read. The conversion itself is done by pdf-oxide, which reads the text stored in the PDF. That text comes out wrong in a few common ways, and pdflite fixes them:

  • A word split across two lines by a hyphen, such as “docu-” and “ment”, is joined back into one word.
  • A table laid out in two columns, such as a bank statement, can come out with its amounts on lines of their own, far from the labels they belong to. pdflite then tries the PDF’s plain-text layer for that page and keeps it if it leaves fewer amounts on their own.
  • A scanned page has no text stored in it, only a picture of the page. pdflite sends such pages to OCR, optical character recognition, which reads the text from the picture.
  • A web page printed to PDF from Medium carries “Press enter or click to view image” lines from the site’s reader, which are removed.

pdf_md does all of this in one call:

from pdflite import pdf_md

md = pdf_md('pdfs/attention_is_all_you_need.pdf', out_path='out'); md[:100] # out_path stores images
# pages = pdf_md('statement.pdf', out_path='out', pages=True)  # one entry per page
Dictionary used where Stream expected, treating as empty stream
Dictionary used where Stream expected, treating as empty stream
Dictionary used where Stream expected, treating as empty stream
Dictionary used where Stream expected, treating as empty stream

'Provided proper attribution is provided, Google hereby grants permission to reproduce the tables and'

out_path is the folder where images found in the PDF are saved, in an images folder inside it; the markdown links to them by relative paths. With pages=True, pdf_md returns a list with one string per page instead of one string, which is what you want when citing page numbers.

Each repair is also exported on its own, so you can use it on markdown from elsewhere: clean_md joins hyphenated words and tidies whitespace, orphan_vals and scrambled_layout detect a reflowed table, fix_layout repairs one, and needs_ocr, thin_text and ocr_parse handle scanned pages. oxide_parse runs the conversion without OCR, and pdf_pages reports how each page was read.

clean_md('a docu-\nment')      # a hyphen split across lines
'a document'
orphan_vals('Opening balance\nFees\n1,240.00\n18.50')   # values cut loose from their labels
2

Install

pip install pdflite

OCR needs liteparse, which is not installed with pdflite: run pip install liteparse if your PDFs include scanned pages. pdflite imports it only when a page needs OCR, and raises an ImportError naming the package if it is missing.

Metadata

Release files for pdflite 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdflite 0.0.4
File Size Uploaded Provenance Actions
pdflite-0.0.4.tar.gz 10.0 kB Without provenance Details for pdflite-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdflite 0.0.4
File Interpreter ABI Platform Actions
pdflite-0.0.4-py3-none-any.whl Python 3 none any Details for pdflite-0.0.4-py3-none-any.whl

Total release size: 20.3 kB

Release files / pdflite-0.0.4.tar.gz

Download URL pdflite-0.0.4.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0a2b7ebdf4cfc478cb22494b196ee34198d857be266eaa6a7e387aae19384a0c
BLAKE2b-256 checksum
How to use checksums
0477c320fad133f60f91d45b9f91d98fd6a6bd9691c97ad88cf94dfd4fe1c116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / pdflite-0.0.4-py3-none-any.whl

Download URL pdflite-0.0.4-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38e0e88a700f595c02872182e9d0e00db472a92081ae1b7c5fa90a9c15f9205d
BLAKE2b-256 checksum
How to use checksums
9890490ba4cadfc042282158ada0eadf1acbcafa8862fcb3f38dc58501e0ced0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for pdflite 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page