Download Latest Version v2.6.7 source code.zip (25.8 MB)
Home / v1.0.9
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2026-02-02 3.7 kB
v1.0.9 source code.tar.gz 2026-02-02 14.7 MB
v1.0.9 source code.zip 2026-02-02 14.7 MB
Totals: 3 Items   29.4 MB 0

This release introduces enhanced table of contents (TOC) extraction capabilities using LLM-powered analysis, enabling more accurate chapter structure detection and hierarchy recognition.

What's Changed

Features

Refactoring

Background

Previously, pdf-craft used statistical analysis to detect TOC pages and extract chapter structure. While effective for basic cases, this approach had limitations in accurately determining chapter hierarchies and handling complex TOC layouts. This release introduces LLM-powered analysis to better understand TOC structure and extract hierarchical information.

How It Works

The new TOC extraction process:

  1. Identify TOC Pages: Uses statistical analysis to detect which pages contain table of contents
  2. Collect All TOC Pages: Gathers all identified TOC pages for comprehensive analysis
  3. LLM Analysis: Passes all TOC pages to an LLM to extract chapter titles and their hierarchical levels
  4. Structure Generation: Uses the extracted hierarchy information to build accurate EPUB navigation structure

This approach combines the efficiency of statistical detection with the semantic understanding capabilities of LLMs, resulting in more accurate chapter organization in the final output.

Usage

The TOC extraction improvements are automatically applied when using the appropriate toc_mode:

:::python
from pdf_craft import transform_epub, BookMeta, TocExtractionMode

# Use AUTO_DETECT for statistical analysis (default for EPUB)
transform_epub(
    pdf_path="input.pdf",
    epub_path="output.epub",
    toc_mode=TocExtractionMode.AUTO_DETECT,
    book_meta=BookMeta(
        title="Book Title",
        authors=["Author"],
    ),
)

# Use LLM_ENHANCED for LLM-powered extraction (requires toc_llm configuration)
from pdf_craft import LLM

toc_llm = LLM(
    key="your-api-key",
    url="https://api.openai.com/v1",
    model="gpt-4",
    token_encoding="cl100k_base",
)

transform_epub(
    pdf_path="input.pdf",
    epub_path="output.epub",
    toc_mode=TocExtractionMode.LLM_ENHANCED,
    toc_llm=toc_llm,
    book_meta=BookMeta(
        title="Book Title",
        authors=["Author"],
    ),
)

Notes

  • Important: When using TocExtractionMode.LLM_ENHANCED, the toc_llm parameter must be configured. The conversion will fail if toc_llm is not provided.
  • This feature is most beneficial for books with complex chapter hierarchies
  • The statistical TOC page detection remains as the first step, with LLM analysis enhancing the extraction quality

Full Changelog: https://github.com/oomol-lab/pdf-craft/compare/v1.0.8...v1.0.9

Source: README.md, updated 2026-02-02