docling-project / docling-project/docling

How to configure Docling Pipeline for DOCX and HTML image extraction and text chunking

Open
#1,347 7 comments 8 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

I have a use case for Docling where I need to create a DocumentConverter that can extract images from PDF, DOCX, and HTML files, while also chunking the file text using a HybridChunker. Currently, my code DOES NOT successfully extract images or chunk text from DOCX and HTML files. I have scoured the docling documentation for answers but I have not been successful. How do I change my code to perform as I desire?

```
from docling.document_converter import DocumentConverter, PdfFormatOption, HTMLFormatOption, WordFormatOption
from docling.chunking import HybridChunker
from docling.datamodel.pipeline_options import PdfPipelineOptions, PaginatedPipelineOptions

# === DOCLING SETUP ===
IMAGE_RESOLUTION_SCALE = 2.0
pdf_pipeline_options = PdfPipelineOptions()
pdf_pipeline_options.generate_page_images = True
pdf_pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE

html_pipeline_options = PaginatedPipelineOptions()
html_pipeline_options.generate_page_images = True
html_pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE

docx_pipeline_options = PaginatedPipelineOptions()
docx_pipeline_options.generate_page_images = True
docx_pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE

converter = DocumentConverter(
allowed_formats=[InputFormat.PDF,
InputFormat.DOCX,
InputFormat.HTML],
format_options={
InputFormat.PDF: PdfFormatOption(pipeline_options=pdf_pipeline_options),
InputFormat.HTML: HTMLFormatOption(pipeline_options=html_pipeline_options),
InputFormat.DOCX: WordFormatOption(pipeline_options=docx_pipeline_options)
}
)

chunker = HybridChunker()

# === PROCESS EACH DOC ===
for doc_path in doc_folder.glob("*"):
if doc_path.suffix.lower() in [".pdf", ".docx", ".html"]:
# === Step 1: Convert with Docling ===
result = converter.convert(str(doc_path))
doc = result.document

# === Step 2: Save page images ===
image_url_map = {}
for page_no, page in doc.pages.items():
image_filename = f"{doc_path.stem}-page-{page_no}.png"
image_path = output_dir / image_filename
page.image.pil_image.save(image_path, format="PNG")

# === Step 3: Chunk the doca ===
chunks = list(chunker.chunk(doc))
```

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.