docling icon indicating copy to clipboard operation
docling copied to clipboard

is it better to use pdfpipeline plus simplepipeline and use pdfpipeline for pdfs and simple pipeline for others? keep in mind that all types of documents may contain complex photos also

Open madmaxtwentytwo opened this issue 1 year ago • 5 comments

give me code snippets for the same and also tell me why is better to use the method suggested by you and also retrieve the relevant content for reference

madmaxtwentytwo avatar Aug 19 '25 17:08 madmaxtwentytwo

Yes, it's best to use pdfpipeline for PDFs and simplepipeline for other formats. Each pipeline is optimized for its document type: pdfpipeline handles PDFs and images with advanced OCR, layout, and enrichment models (ideal for complex photos), while simplepipeline is designed for formats like DOCX, HTML, and Markdown that can be directly converted to DoclingDocument. This approach improves reliability and modularity, and lets you fine-tune image extraction for PDFs where photo handling is more complex reference.

Here's a practical code snippet showing how to set up DocumentConverter to route PDFs to pdfpipeline (with image extraction options) and other formats to simplepipeline:

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

pdf_options = PdfPipelineOptions(
    generate_page_images=False,         # Set True if you want full-page scans
    generate_picture_images=True,       # Extract individual photos/figures
    images_scale=1.0,                   # Use higher for better resolution if needed
    do_picture_description=True,        # Enable image captioning (optional)
    min_picture_page_surface_ratio=0    # Process all images, not just large ones
)

converter = DocumentConverter(
    allowed_formats=[InputFormat.PDF, InputFormat.DOCX, InputFormat.HTML],
    format_options={
        InputFormat.PDF: PdfFormatOption(pipeline_options=pdf_options),
        InputFormat.DOCX: WordFormatOption(),  # SimplePipeline is used by default
        InputFormat.HTML: WordFormatOption(),  # Or use other format options as needed
    }
)

# Usage:
# result = converter.convert(source)

Example and discussion | Image extraction options

Why this is better:

  • pdfpipeline is specialized for PDFs, supporting complex layouts and advanced image extraction (including enrichment like classification and captioning) reference.
  • simplepipeline is lightweight and direct for DOCX, HTML, and similar formats, but does not support advanced photo extraction like pdfpipeline reference.
  • You can configure pdfpipeline to extract all images, only large ones, or add enrichment steps as needed. This flexibility is crucial for documents with complex photos reference.
  • Using both pipelines lets you optimize performance and resource usage: enable only the image types and enrichment steps you need, and profile pipeline timings for your environment reference.

For more details on pipeline configuration and best practices, see:

Let me know if you need more specific configuration examples or advice for a particular document type!

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about docling Share Dosu with your team

dosubot[bot] avatar Aug 19 '25 17:08 dosubot[bot]

does simplepipeline has any settings which can effect the quality

madmaxtwentytwo avatar Aug 19 '25 17:08 madmaxtwentytwo

SimplePipeline doesn't have configurable settings that affect output quality—its job is to convert formats like DOCX, HTML, and Markdown directly to DoclingDocument using the backend's default logic, without page-level processing or enrichment steps. This means you can't tune image extraction, resolution, or advanced OCR options like you can with pdfpipeline for PDFs. The quality is determined by the internal converter for each format (for example, python-docx for DOCX), not by pipeline options or settings you can adjust source.

If you need more control over extraction quality (especially for images or OCR), use pdfpipeline for PDFs, or consider preprocessing your documents before using SimplePipeline. For reference, see the pipeline design and limitations here.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about docling Share Dosu with your team

dosubot[bot] avatar Aug 19 '25 17:08 dosubot[bot]

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

pdf_options = PdfPipelineOptions( generate_page_images=False, # Set True if you want full-page scans generate_picture_images=True, # Extract individual photos/figures images_scale=1.0, # Use higher for better resolution if needed do_picture_description=True, # Enable image captioning (optional) min_picture_page_surface_ratio=0 # Process all images, not just large ones )

converter = DocumentConverter( allowed_formats=[InputFormat.PDF, InputFormat.DOCX, InputFormat.HTML], format_options={ InputFormat.PDF: PdfFormatOption(pipeline_options=pdf_options), InputFormat.DOCX: WordFormatOption(), # SimplePipeline is used by default InputFormat.HTML: WordFormatOption(), # Or use other format options as needed } )

Usage:

result = converter.convert(source)

extend this code for ppt and other types of documents also

madmaxtwentytwo avatar Aug 19 '25 17:08 madmaxtwentytwo

You can extend your DocumentConverter setup to support PPTX and other formats (like XLSX, CSV, Markdown, AsciiDoc, images, audio, etc.) by adding their InputFormat values to allowed_formats and using the corresponding FormatOption classes. For most office formats (DOCX, PPTX, XLSX, CSV, MD, HTML, etc.), Docling uses SimplePipeline with a format-specific backend, which extracts text, images, tables, and notes directly but does not offer advanced image extraction or enrichment settings like pdfpipeline does for PDFs. The quality for these formats is determined by the backend logic, not by pipeline options—so you can't tune image extraction or enrichment for PPTX, DOCX, etc. via pipeline settings [source].

Here’s an extended code snippet:

from docling.document_converter import (
    DocumentConverter,
    PdfFormatOption,
    WordFormatOption,
    PowerpointFormatOption,
    ExcelFormatOption,
    CsvFormatOption,
    MarkdownFormatOption,
    AsciiDocFormatOption,
    HTMLFormatOption,
    ImageFormatOption,
    AudioFormatOption,
)
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.datamodel.base_models import InputFormat

pdf_options = PdfPipelineOptions(
    generate_page_images=False,
    generate_picture_images=True,
    images_scale=1.0,
    do_picture_description=True,
    min_picture_page_surface_ratio=0
)

converter = DocumentConverter(
    allowed_formats=[
        InputFormat.PDF,
        InputFormat.DOCX,
        InputFormat.PPTX,
        InputFormat.XLSX,
        InputFormat.CSV,
        InputFormat.MD,
        InputFormat.ASCIIDOC,
        InputFormat.HTML,
        InputFormat.IMAGE,
        InputFormat.AUDIO,
    ],
    format_options={
        InputFormat.PDF: PdfFormatOption(pipeline_options=pdf_options),
        InputFormat.DOCX: WordFormatOption(),      # SimplePipeline for DOCX
        InputFormat.PPTX: PowerpointFormatOption(),# SimplePipeline for PPTX
        InputFormat.XLSX: ExcelFormatOption(),     # SimplePipeline for XLSX
        InputFormat.CSV: CsvFormatOption(),        # SimplePipeline for CSV
        InputFormat.MD: MarkdownFormatOption(),    # SimplePipeline for Markdown
        InputFormat.ASCIIDOC: AsciiDocFormatOption(), # SimplePipeline for AsciiDoc
        InputFormat.HTML: HTMLFormatOption(),      # SimplePipeline for HTML
        InputFormat.IMAGE: ImageFormatOption(),    # PDF pipeline for images
        InputFormat.AUDIO: AudioFormatOption(),    # ASR pipeline for audio
    }
)

# Usage:
# result = converter.convert(source)

For PPTX, XLSX, DOCX, etc., SimplePipeline extracts slides, text, images, tables, and notes using the backend (e.g., MsPowerpointDocumentBackend for PPTX), but you can't configure image extraction or enrichment at the pipeline level [source]. If you need advanced image handling (like OCR, classification, or captioning), only PDF/image formats support those via PdfPipelineOptions [source].

This modular approach lets you process all major document types in a unified way, with optimal pipelines for each format. For more details, see the DocumentConverter implementation and MsPowerpointDocumentBackend.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about docling with Dosu Add Dosu to your team

dosubot[bot] avatar Aug 19 '25 17:08 dosubot[bot]