Extract structured text from PDFs
Project description
frompdf
frompdf is a simple CLI tool for extracting structured text from PDFs.
The initial and primary output format is Markdown, with additional output formats planned. frompdf uses robust heuristics to detect paragraphs, headings at various levels, block quotes, and other document features. Running headers and footers are detected and removed, while page numbers can optionally be exported as metadata.
These heuristics can never be perfect, but they should often provide a useful approximation of the actual document content — one that is more useful than plain text extraction for RAG and similar workflows, or for turning read-only PDFs into editable structured text.
While ML-based alternatives such as Docling may handle some details better, they are slower and have considerably higher computational overhead. frompdf's heuristics will not get every detail right, but they are fast, robust, and easy to run locally.
frompdf is released under the permissive MIT License. This can make it easier to use, modify, and integrate than tools based on PyMuPDF, which is available under the GNU AGPL or a commercial license.
What frompdf does right now
The current version provides one command:
frompdf file.pdf- extract Markdown from a PDF
For an input named file.pdf, the command writes:
file.md- Markdown output
With diagnostic options, it can also write:
file-lines.csv- extracted line records with page, block, geometry, font size, and weight datafile-pagenos.csv- visible page numbers detected in headers or footers, if any are found
If file.md already exists, frompdf renames it to file.md.bak before
writing the new output. Overwriting an existing .bak file is allowed.
Current Markdown Features
frompdf currently detects and serializes:
- paragraphs
- headings, based mostly on font size plus a document-relative font-weight boost
- block quotes, based on indentation
- repeated headers and footers, which are removed from the Markdown output
- visible page numbers found in removed headers or footers
The internal block model tracks the raw PDF page number and, when available, the visible page number for each block.
Requirements
- Python 3.11 or newer
pdftext, installed through this package's dependencies
Installation
For local use from a checkout of this repository:
pip install -e .
That installs the package in editable mode and makes the frompdf command
available in the active Python environment.
If you prefer pipx for command-line tools, use editable mode when installing
from a local checkout so the command sees local code changes:
pipx install -e .
Usage
Convert a PDF:
frompdf ./document.pdf
Example output:
document.md written
Write diagnostic CSV files as well:
frompdf --dump-lines --dump-pagenos ./document.pdf
Example output:
document-lines.csv written
document-pagenos.csv written
document.md written
--dump-lines writes the extracted line records. --dump-pagenos writes the
page-number CSV only when visible page numbers were detected.
Limitations
PDFs do not contain document structure directly, so most higher-level structure has to be inferred. Current limitations include:
- heading detection is heuristic and can miss headings or over-detect short emphasized text
- block quote detection is conservative and currently relies on indentation
- lists, tables, captions, footnotes, and code blocks are not modeled as dedicated block types yet
- multi-column and heavily designed PDFs can still produce awkward reading order
- header and footer removal depends on repetition and page-position heuristics
The diagnostic CSV files are part of the workflow: they make it easier to see why a specific line or block was classified the way it was.
Planned Direction
Planned next improvements include:
- detection of lists, footnotes, and preformatted blocks
- dehyphenation of words split across line breaks
- better detection of paragraph boundaries, including merging paragraphs that span more than one page
- correction of font-encoding and ligature-related text extraction errors
- better support for multi-column PDFs
- additional output formats such as HTML, EPUB, ODT, and DOCX
Development
See CONTRIBUTING.md for development setup, style rules, testing commands, and guidance for contributors and coding agents.
License
frompdf is distributed under the MIT license. See LICENSE.txt.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file frompdf-0.1.0.tar.gz.
File metadata
- Download URL: frompdf-0.1.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5432904cfd7d29b76aa83570ca30216cad13deb9347962352325bd87a40fc185
|
|
| MD5 |
ef80b5b2f6e54e9d30fabf75d0943df9
|
|
| BLAKE2b-256 |
1bffcdba9db38b7ab98149141f80eee8ed8eea93847b84fba683ed7ab338917e
|
File details
Details for the file frompdf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: frompdf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f327c0c96e96b6c6d6317d3916213847433abc15589acec3bba412d38c3d00f2
|
|
| MD5 |
cda01a6d1d0f26a86ca942eb53754e36
|
|
| BLAKE2b-256 |
06fab450cf1d6f54e0eb62af901db776d160b05270da4c5766d1280ef2a288f7
|