Doclingdocling 2.127.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson

The switches on the PDF pipeline

The PDF conversion so far used the default settings. Those defaults do work you may not need, and the way to change them is one object passed in at converter construction.

A converter maps each format to the options for that format. Change the PDF ones and the rest of the course keeps working unchanged.

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

options = PdfPipelineOptions()
converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)})

Three imports and two objects, and it is the shape every customisation in this lesson takes. PdfFormatOption is the wrapper that ties one set of options to one format.

What is on by default

Example
from docling.datamodel.pipeline_options import PdfPipelineOptions

defaults = PdfPipelineOptions()
print("ocr            ", defaults.do_ocr)
print("table structure", defaults.do_table_structure)
print("page images    ", defaults.generate_page_images)

OCR and table structure are on, page images are off. So every PDF you have converted so far ran an optical character recognition pass looking for text that is a picture of text.

Turning OCR off

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

options = PdfPipelineOptions(do_ocr=False)
quick = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)})
print(quick.convert("returns.pdf").document.export_to_markdown()[:38])

Identical text, noticeably faster. This PDF has real text in it, so there was never anything for OCR to find; the pass ran anyway and found nothing. On a folder of files like this one, turning it off is free speed.

Turn it off only when you know. A scanned page is a picture, and with do_ocr=False it converts to a document with no text in it at all. No error, no warning, an empty document. Lesson 17 is how you notice.

Page images

Example
options = PdfPipelineOptions(generate_page_images=True, images_scale=2.0)
shown = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)})
page = shown.convert("returns.pdf").document.pages[1]
print(page.image.pil_image.size, "at", page.image.dpi, "dpi")

An image per page, rendered at twice the document's own resolution. A page is 612 points wide and 72 points is an inch, so scale 2 gives 144 dots per inch and a 1224 pixel image. That image plus the boxes from lesson 14 is everything you need to draw a highlight over the original page.

The rest of the switches

OptionDefaultWhat it does
do_ocrTrueLook for text that is a picture of text
do_table_structureTrueRun the table model to find rows and columns
table_structure_options.modeaccurateSwap to fast for a quicker, rougher table
generate_page_imagesFalseKeep a rendered image of each page
images_scale1.0How large those images are
enable_remote_servicesFalseAllow a step that sends your document away

The last one is a lock rather than a feature. Docling runs everything locally unless you turn that on, and a step that would call out to a hosted model raises instead. Lesson 26 is the one place this course goes near it.

Try it yourself
  • Set table_structure_options.mode to TableFormerMode.FAST and convert again.
  • Convert with do_table_structure=False and check the markdown is unchanged for this file.
  • Render the pages at images_scale=1.0 and compare the pixel size.

Every expert started right here.