oomol-lab/pdf-craft

PDF craft can convert PDF files into various other formats. This project will focus on processing PDF files of scanned books.

PDF Craft – Turn scanned PDFs into editable Markdown or EPUB (with translation)

What it does

PDF Craft is a Python library that takes scanned PDF books or technical documents and extracts their content – text, images, tables, formulas, footnotes, and the table‑of‑contents. The extracted material can be saved as:

  • Markdown (plain‑text with image assets) – easy to edit, search, or feed into other pipelines.
  • EPUB – a ready‑to‑read ebook with proper metadata and navigation.
  • Translated versions – the library can call a text‑generation LLM to translate the extracted text, producing bilingual Markdown/EPUB or even a new PDF with the translation rendered back onto the original pages.

Why it matters

Scanned books are usually locked in image‑only PDFs, making them hard to search, edit, or repurpose. PDF Craft automates the whole pipeline:

  1. OCR – uses DeepSeek OCR (or other supported back‑ends) either via a remote API or locally on a CUDA‑enabled GPU.
  2. Structure detection – recognises chapters, TOC, footnotes, tables, formulas, and images, preserving the logical layout.
  3. Export – produces clean Markdown or a standards‑compliant EPUB, optionally enriched with metadata extracted by a small LLM.
  4. Translation – leverages a separate LLM to translate the text, supporting bilingual output or a fully translated PDF.

This saves hours of manual re‑typing and enables downstream tasks such as summarisation, knowledge‑graph creation, or feeding the text into other AI models.

How to use it (quick‑start)

# Install the package (remote OCR works out‑of‑the‑box)
python -m pip install pdf-craft
from pdf_craft import DeepSeekOCRVendorConfig, PDFCraft, PDFOptions

craft = PDFCraft(
    pdf=PDFOptions(
        ocr=DeepSeekOCRVendorConfig(
            base_url="https://example.com/v1",  # your OCR service endpoint
            api_key="your-api-key",
            model="deepseek-ocr",
        ),
    ),
)

# Convert to Markdown
craft.convert_pdf_to_markdown("input.pdf", "output.md")

# Or convert to EPUB
craft.convert_pdf_to_epub("input.pdf", "output.epub")

For async applications use AsyncPDFCraft and await the same methods.

Local GPU mode

If you have an NVIDIA GPU you can install the extra dependencies:

python -m pip install "pdf-craft[local]"

Then the library will load the DeepSeek OCR models from Hugging Face locally.

Key components

Component Role
DeepSeek OCR / DeepSeek OCR 2 / Unlimited OCR Text recognition back‑ends (remote or local).
XMLTranslator Calls a text‑generation LLM to translate extracted content.
.pcex extraction file Serialized intermediate representation that can be reused for later rendering, translation, or sharing.
Ghostscript + fonts Required when writing the translated text back onto the original PDF pages.

When to choose which usage path

Path Best for Requirements
Online demo Quick try‑out without installing anything. Web browser.
Python + remote OCR Developers who prefer not to run heavy OCR models locally. Poppler, OCR service URL & API key.
Python + local OCR Full‑offline processing, batch jobs, or privacy‑sensitive data. Poppler, CUDA‑enabled GPU, sufficient VRAM, model files.

Documentation & ecosystem

  • Installation guide – Poppler setup, GPU requirements, extra‑install for local OCR.
  • OCR back‑ends – How to configure remote services or download local models.
  • PDF conversion & translation – Options for metadata extraction, bilingual EPUB, and PDF‑back‑translation.
  • EPUB translation – Replace or append translated text.
  • API reference – Types like PDFCraft, AsyncPDFCraft, DeepSeekOCRVendorConfig, PDFOptions.
  • .pcex format – Portable extraction files for reuse.
  • Troubleshooting – Common install and conversion issues.

Who might use it

  • Researchers & students who need searchable, editable versions of scanned papers or books.
  • Developers building reading apps that want to ingest legacy PDFs.
  • Content creators looking to translate older books into new languages.
  • Knowledge‑graph projects (e.g., the linked Wiki Graph repo) that need clean text to build summaries or graphs.

PDF Craft is open‑source (MIT) and builds on DeepSeek OCR, Unlimited OCR, and other community libraries.

Related

  • Project
  • Project
  • Project
  • Project
  • Project