Skip to main content

PDF to structured text with page segmentation

Project description

DocBlocks — Layout-Preserving PDF Text Extraction

DocBlocks is a Python library for extracting text from digitally generated PDFs while preserving their visual reading order and page structure. It avoids the alignment distortions found in traditional PDF extractors.

Note: DocBlocks works only with computer-generated (digital) PDFs.
It does not support scanned/image PDFs at this time.


Purpose

Most extraction libraries produce output that is:

  • misaligned
  • reordered
  • merged across columns
  • missing sections

DocBlocks solves this by providing:

  • accurate reading order
  • non-destructive extraction
  • page-based segmentation
  • zero content modification

Final mission: no more ugly alignment at the end.


Guarantees

DocBlocks guarantees:

  • no text modification
  • no text deletion
  • no page merging
  • no reordering beyond true reading order
  • one page’s content will never interfere with another page

This ensures perfect segmentation for AI/ML pipelines, RAG systems, or document processing.


Current Limitations

DocBlocks does not support:

  • scanned/image PDFs
  • OCR-based text extraction
  • non-PDF formats (Word, images, HTML)

This limitation is intentional to guarantee perfect handling of digital text PDFs.


Roadmap (Planned for End of February Release)

The upcoming version will include:

  • support for additional document formats
  • OCR engine for scanned documents
  • richer layout information
  • improved block detection

OCR engine names are intentionally not mentioned — expect powerful, production-grade OCR.


Installation

pip install docblocks

Requires Python 3.8+


Usage

Extract text into memory

import docblocks

text = docblocks.extract(r"document.pdf")
print(text)

Convert PDF → TXT file

import docblocks

docblocks.convert(
    r"document.pdf",
    r"output.txt"
)

You must use r"..." (raw strings) for Windows paths to avoid escape issues.


Output Format

DocBlocks ensures:

  • clean page segmentation
  • pure reading order
  • no cross-page interference
  • no ugly alignment errors

Example output:

┌──────── PAGE 1 ─────────┐
This is page one content...
└──────────────────────────┘

┌──────── PAGE 2 ─────────┐
This is page two content...
└──────────────────────────┘

Notice that:

Page 1 content never flows into Page 2, and Page 2 never leaks into Page 1.


Best For

DocBlocks is ideal for:

  • research papers
  • legal & policy docs
  • technical manuals
  • structured reports
  • AI preprocessing (RAG / LLM input)

License

MIT — free for commercial & academic use.


Vision

DocBlocks exists for one purpose:

“No more ugly alignment at the end.”


Contributing

Issues and suggestions are welcome:

https://github.com/vishalp-dev24/DocBlocks.git

Pull requests, feedback, and feature requests are appreciated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docblocks-0.1.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docblocks-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file docblocks-0.1.1.tar.gz.

File metadata

  • Download URL: docblocks-0.1.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for docblocks-0.1.1.tar.gz
Algorithm Hash digest
SHA256 51069260be77ee944d36b091e65d4fd5f57eaabf763b3d682b0f283c0ab16bac
MD5 49a3896cbec6a20e7f204256faa37f5c
BLAKE2b-256 427c90530f30441a8a2590f7591418de88890c1c178a68a1ce4cac20fd4ae016

See more details on using hashes here.

File details

Details for the file docblocks-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: docblocks-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for docblocks-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 330ae5809724c51fb3f3e9130440c67fc43953e3d81c56058efa10ced1ee6ee7
MD5 5acad3a4d33f402110518a8596a21437
BLAKE2b-256 1150d91eafd8f09c08858763ffeac6a9c97fd92b7439f8fd914323f9cd9c0d2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page