Performance Difference Between Docling and pdftotext for PDF Extraction

pdftotext extracts a 103-page PDF in 0.1 seconds as flat text, while Docling requires 164 seconds (1.6 seconds per page) to preserve tables and code blocks as structured Markdown.

The book-to-skill repository implements dual PDF extraction back-ends that trade raw processing speed for structural fidelity. Understanding the performance difference between Docling and pdftotext for PDF extraction helps you select the optimal approach for technical documentation versus prose-heavy books.

Benchmark Results: Milliseconds vs Minutes

According to the measurements documented in docs/performance.md (lines 27-34), these backends exhibit a performance differential exceeding three orders of magnitude when processing a 103-page technical PDF containing tables and code blocks.

pdftotext: Native Speed Optimization

The extract_with_pdftotext function in book_to_skill/parsers/pdf.py (lines 75-88) serves as a thin wrapper around the poppler-utils system binary. It invokes pdftotext with -layout -enc UTF-8 flags to stream PDF content directly into UTF-8 encoded text.

  • Processing time: Approximately 0.1 seconds for a 103-page document
  • Implementation: Compiled C binary called via subprocess
  • Output characteristics: Plain text only; tables, code blocks, and page geometry are flattened into a continuous text flow
  • Structural fidelity: None—visual layout is discarded in favor of extraction velocity

Docling: Layout-Aware Document Understanding

The extract_with_docling function in book_to_skill/parsers/pdf.py (lines 45-64) utilizes the Python docling library to construct a complete document model. It initializes a DocumentConverter with PdfPipelineOptions configured for OCR-disabled, table-structure extraction and technical mode parsing.

  • Processing time: Approximately 164 seconds total (1.6 seconds per page)
  • Implementation: Pure Python library with page-by-page layout analysis
  • Output characteristics: Semantic Markdown preserving approximately 48 tables and 36 code blocks from the benchmark document
  • Structural fidelity: High—rebuilds tables and code blocks as native Markdown structures

Architectural Reasons for the Performance Gap

The 1,600x speed difference stems from fundamentally opposing design philosophies.

pdftotext operates as a stream processor. The native C implementation extracts text objects directly from the PDF content stream without rendering pages or analyzing spatial relationships. This approach discards all positional metadata and structural hints embedded in the PDF, resulting in minimal CPU overhead.

Docling performs comprehensive document reconstruction. For each page, it analyzes visual layout, detects table boundaries, infers cell structures, identifies code block regions, and rebuilds the document as hierarchical Markdown. This multi-stage pipeline requires substantial CPU cycles to interpret visual semantics that pdftotext ignores entirely.

Selecting the Appropriate Extraction Backend

The orchestration logic in book_to_skill/utils.py (lines 58-67) automatically manages backend selection based on the extraction_mode parameter. You can also invoke these functions directly to control the speed-fidelity trade-off.

When to Use pdftotext

Select this backend for prose-heavy books and speed-critical pipelines:

  • Processing novels, essays, or articles without tabular data
  • Building search indices where raw text tokens suffice
  • Operating on resource-constrained environments where 0.1-second latency matters more than structure

When to Use Docling

Select this backend for technical manuals, academic papers, and documentation analysis:

  • Extracting programming books containing code blocks that must retain formatting
  • Processing research papers with data tables requiring preservation
  • Preparing content for Markdown-based knowledge bases where table structure carries semantic meaning

Implementation Examples

Both extraction functions return None when the required external tool or library is unavailable, enabling graceful fallback handling in production pipelines.

Extract plain text using the high-speed pdftotext backend:

from book_to_skill.parsers.pdf import extract_with_pdftotext

pdf_path = "business_proposal.pdf"
text = extract_with_pdftotext(pdf_path)
if text:
    print("Plain text extracted in ~0.1 seconds:")
    print(text[:500])

Extract structured Markdown using the layout-aware Docling backend:

from book_to_skill.parsers.pdf import extract_with_docling

pdf_path = "api_reference.pdf"
markdown = extract_with_docling(pdf_path)
if markdown:
    print("Structured Markdown extracted in ~1.6s per page:")
    print(markdown[:500])

Backend Orchestration and Fallback Behavior

When extraction_mode is set to "technical", the system defined in book_to_skill/utils.py attempts Docling first to maximize structural extraction. If Docling fails to import or returns empty output, the orchestrator automatically falls back to pdftotext to ensure the pipeline completes successfully. This design guarantees that technical books receive rich Markdown formatting when possible, while maintaining reliability through the faster native binary.

Summary

  • pdftotext processes a 103-page PDF in 0.1 seconds via a compiled C backend, returning plain text with no structural preservation.
  • Docling requires 164 seconds (1.6 seconds per page) to generate Markdown, preserving approximately 48 tables and 36 code blocks through Python-based layout analysis.
  • Choose pdftotext for velocity-critical applications processing prose; choose Docling for technical documentation requiring table and code block fidelity.
  • The orchestrator in book_to_skill/utils.py automatically manages fallback from Docling to pdftotext when operating in technical mode.

Frequently Asked Questions

How significant is the performance difference between Docling and pdftotext?

Docling is approximately 1,600 times slower than pdftotext for typical technical documents. According to docs/performance.md, pdftotext completes a 103-page PDF in 0.1 seconds, while Docling averages 1.6 seconds per page, totaling 164 seconds for the same document. This gap reflects the computational cost of layout analysis versus raw text streaming.

Does pdftotext preserve tables and code formatting?

No. The extract_with_pdftotext implementation in book_to_skill/parsers/pdf.py returns only plain text, flattening tables and code blocks into continuous prose. Docling specifically addresses this limitation by analyzing page geometry to reconstruct approximately 48 tables and 36 code blocks as native Markdown elements in the benchmark test.

Can the system automatically switch between extraction methods?

Yes. The orchestration logic in book_to_skill/utils.py (lines 58-67) implements an automatic fallback system. When extraction_mode equals "technical", it attempts Docling first; if the library is unavailable or produces no output, it seamlessly falls back to pdftotext to ensure extraction proceeds without manual intervention.

Where are the performance benchmarks documented?

The specific timing measurements comparing 0.1 seconds versus 164 seconds for identical 103-page PDFs are located in docs/performance.md (lines 27-34). These benchmarks reflect real-world extraction times on technical documentation containing mixed content types including tables, code snippets, and formatted text.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →