Dosu LogoDosu Logo
Ask
Join our Discord
DoclingPublic
IBM Docling
DocumentsDocling
When processing large PDFs (700+ pages) with Docling's StandardPdfPipeline, what causes the `std::bad_alloc` errors and what are the recommended workarounds?
When processing large PDFs (700+ pages) with Docling's StandardPdfPipeline, what causes the `std::bad_alloc` errors and what are the recommended workarounds?
Type
Answer
Status
Published
Created
Apr 17, 2026
Updated
Apr 17, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Cause of std::bad_alloc in Docling#

The std::bad_alloc errors occur because Docling's StandardPdfPipeline uses the docling-parse C++ backend, which loads page images into memory for layout detection, OCR, and table structure analysis. When processing large PDFs (700+ pages with images and math formulas), the C++ backend accumulates memory internally and eventually exhausts available RAM — even on machines with 32GB RAM.

This issue is specific to PDFs and image files. DOCX, XLSX, and PPTX use SimplePipeline (direct XML parsing) and are not affected.


Recommended Workarounds#

1. Process in page range batches#

from docling.document_converter import DocumentConverter
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.datamodel.base_models import InputFormat
from docling.document_converter import PdfFormatOption

pipeline_options = PdfPipelineOptions(
    generate_page_images=False,
    generate_picture_images=False,
    ocr_batch_size=1,
    layout_batch_size=1,
    table_batch_size=1,
)

# Process 50 pages at a time, creating a fresh converter per batch
for start in range(1, 701, 50):
    end = min(start + 49, 700)
    converter = DocumentConverter(
        format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
    )
    result = converter.convert("your_large.pdf", page_range=(start, end))
    # process result...
    del converter # help garbage collection

Note: Create a new DocumentConverter instance per batch, as the backend may retain caches between calls.

2. Switch to the pypdfium2 backend#

This resolves memory accumulation but has trade-offs for complex/math-heavy PDFs (more fragmented table cell extraction):

from docling.backend.pypdfium2_backend import PyPdfiumDocumentBackend

converter = DocumentConverter(
    format_options={
        InputFormat.PDF: PdfFormatOption(
            backend=PyPdfiumDocumentBackend,
            pipeline_options=PdfPipelineOptions(
                do_table_structure=True,
                do_cell_matching=False, # recommended for pypdfium2
            )
        )
    }
)

Known Limitation: Cross-Page Tables#

When batching with page_range, tables that span a batch boundary (e.g., starts on page 100 and continues on page 101) produce separate TableItem objects with no continuation metadata. Docling has no built-in cross-page table merging. The recommended mitigation is:

  1. Use pypdfium2 externally to extract PDF bookmarks/outlines and split at chapter/section boundaries instead of arbitrary page counts.
  2. Implement LLM-assisted post-processing to detect and merge tables at batch boundaries.

Summary Table#

BackendMemoryTable Quality (Math PDFs)
docling-parse (default)Accumulates ❌High ✅
pypdfium2Efficient ✅Reduced ❌

For math-heavy academic papers, docling-parse + page_range batching is preferred to preserve table extraction quality.

Documents
Building a Modular IDP Pipeline with Docling Components
Can I use a custom OCR model in Docling, and how do I set its path in the pipeline options?
Can docling-serve fetch documents from object storage (e.g., S3)?
Comment corriger la phrase : "Je suis allé à l'école en pied et mains je parte par quotidien des beaucoup de kilomètres cela est importante" ?
Content Layers
Docling MCP in Docling Serve
Does Docling automatically detect the language of a document when sending images to Tesseract OCR, and how can it be configured?
How can I enable and use GPU acceleration with Docling?
How can I find page numbers and bounding box information for content in a chunk produced by the hybrid chunker, and what is the structure of the doc_items list within a chunk?
How can I improve the resolution or quality of images extracted from a PDF using docling?
How can I set up and run docling-serve on a MacBook Pro using Docker, and what performance and stability considerations should I be aware of?
How can I use Docling's REST API to convert a PDF from a URL to Markdown with OpenAI-generated image descriptions, and is base64 encoding required for URL sources?
How can I use granite-docling to process all PDFs in a directory and output doctags?
How can a student build a local, open-source LLM-based system to extract and analyze technical PDF documents (PMS/IDC) and generate instrumentation datasheets, using Python on a PC with limited resources?
How can a student build a local, open-source, privacy-preserving AI system to extract and query technical PDF documents (PMS/IDC) on a PC with limited resources?
How can you make Docling read/understand images embedded in a DOCX file, and what is the correct code to use the VlmPipeline for this purpose?
How can you mount a PersistentVolumeClaim (PVC) in docling-serve on OpenShift to store EasyOCR models, and what steps are required to ensure docling-serve can access these models?
How can you use Docling's REST API to convert a PDF to Markdown and generate image descriptions using an OpenAI model?
How do I set up a complete multi-format document processing pipeline using Docling that handles technical PDFs, HTML files, images, videos, audio, codebases, and schematics, and exports everything to organized agent-friendly markdown files?
How do you install and use Docling in Python on WSL2, including integration with an AI agent?
How do you use HybridChunker in Docling, including saving and reloading the converted document?
How does Docling reconstruct reading order without using a large language model (LLM) call in an unsupervised manner?
How does Docling support parallel/multiprocessing for document conversion, and what do the key performance parameters (`page_chunk_size`, `doc_batch_concurrency`, `doc_batch_size`) do?
How to properly enable `enable_remote_services` in Docling Serve (CPU image) to use an external OpenAI-compatible API for picture description and formula enrichment, and what is the correct config format?
Models handling in Docling Serve
No Docling, o uso de CUDA é obrigatório para processar PDFs com extração de texto e descrição de imagens, ou é opcional?
Quais são as melhores opções de OCR para extração de tabelas financeiras complexas em PDFs usando Docling, incluindo alternativas externas e integração com plugins?
Quelle est l'origine et le statut des êtres mathématiques selon Platon et John Stuart Mill ?
What are all the parameters of HybridChunker in Docling, and how do you use it with a custom tokenizer?
What are all the pipelines that exist in Docling, including their purposes, selection criteria, and how they handle scanned documents?
What are the detailed pipeline options and processing behaviors for PDF, DOCX, PPTX, and XLSX files in the Python SDK?
What are the differences between `vlm_pipeline_model_local` and `picture_description_local` in Docling, and how do image descriptions, OCR, and table extraction work together? Also, how do the `include_annotations` and `mark_annotations` properties affect exported output?
What are the steps to convert a complex payment advice PDF to Excel using Docling?
What does 'RFLP' stand for or refer to?
What is the best practice for extracting text from a mixed PDF (digital + scanned pages) for enterprise financial document processing without a GPU and with limited costs?
What is the best practice for processing a mixed PDF (digital + scanned pages) containing sensitive financial data in Docling, given no GPU and limited cost?
What is the general sentiment expressed about the messy nature of documents and content in the Docling project?
What is the recommended Azure deployment option for a Docling-based Python SDK application using a custom Dockerfile with PyTorch and OCR, and why?
What is the recommended architecture and implementation for processing a mixed PDF bundle (digital + scanned pages) for an enterprise financial payment verification system (like MRT Jakarta's AI-Augmented Payment Flow), with constraints of no GPU and limited cost?
When processing large PDFs (700+ pages) with Docling's StandardPdfPipeline, what causes the `std::bad_alloc` errors and what are the recommended workarounds?
Which is the better option for running Docling: using 'docling serve' in Azure Container Apps or code-based deployment in Azure Function App (Windows Premium plan)?
Why are bounding boxes not available for items (such as images, tables, text) when using VlmPipeline with certain VLM presets (like Qwen/Markdown)?
Zoom on Layer 1 (L1): Layout Detection & Routing in a Modular IDP Pipeline
skill.md
คู่มือการดึงรูปภาพจาก PDF และสร้าง Markdown พร้อม Alternative Text ด้วย Docling