docling-project / docling-project/docling

How to optimize PDF to Markdown extraction for large PDFs?

Open
#2,120 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

Hi everyone,

I'm working with a 100-page PDF and using the codebase below to extract each page's content in Markdown format. The process includes OCR and table structure extraction using PdfPipelineOptions, and it's taking around 1080 seconds (18 minutes) for just 100 pages — which is far too slow for my use case.

Goal:

Improve performance so it can process 1000 pages within 1 minute.

```
# Set up pipeline options
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.do_table_structure = True
pipeline_options.table_structure_options.do_cell_matching = True
pipeline_options.table_structure_options.mode = TableFormerMode.ACCURATE

# Create a DocumentConverter instance
converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
}
)

def load_pdf_using_docling(file: bytes, filename: str) -> List[Document]:
stream = DocumentStream(name=filename, stream=BytesIO(file))
result = converter.convert(stream)
num_pages = len(result.document.pages)
markdown_pages = []
for page_no in range(1, num_pages + 1):
md = result.document.export_to_markdown(
page_no=page_no,
image_mode="placeholder",
include_annotations=True
)
doc = Document(page_content=md, metadata={"page": page_no})
markdown_pages.append(doc)
return markdown_pages
```
What I've tried / observed:

Turning off do_ocr speeds things up, but I lose crucial content (PDFs are scanned).

Reducing table_structure_options.mode to a faster setting helps a bit but sacrifices accuracy.

The bottleneck seems to be both convert(stream) and export_to_markdown(...) loop.

What I'm looking for:

Any suggestions to optimize this codebase for performance.

Is there a way to parallelize per-page processing with this library?

Are there alternative libraries or pipeline configurations that could achieve similar accuracy but much faster?

Any hardware considerations or GPU acceleration possible with this stack?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.