mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 20:58:11 +00:00
docs: Describe examples (#2262)
* Update .py examples with clearer guidance, update out of date imports and calls Signed-off-by: Mingxuan Zhao <43148277+mingxzhao@users.noreply.github.com> * Fix minimal.py string error, fix ruff format error Signed-off-by: Mingxuan Zhao <43148277+mingxzhao@users.noreply.github.com> * fix more CI issues Signed-off-by: Mingxuan Zhao <43148277+mingxzhao@users.noreply.github.com> --------- Signed-off-by: Mingxuan Zhao <43148277+mingxzhao@users.noreply.github.com>
This commit is contained in:
31
docs/examples/full_page_ocr.py
vendored
31
docs/examples/full_page_ocr.py
vendored
@@ -1,3 +1,31 @@
|
||||
# %% [markdown]
|
||||
# Force full-page OCR on a PDF using different OCR backends.
|
||||
#
|
||||
# What this example does
|
||||
# - Enables full-page OCR and table structure extraction for a sample PDF.
|
||||
# - Demonstrates how to switch between OCR backends via `ocr_options`.
|
||||
#
|
||||
# Prerequisites
|
||||
# - Install Docling and the desired OCR backend's dependencies (Tesseract, EasyOCR,
|
||||
# RapidOCR, or macOS OCR).
|
||||
#
|
||||
# How to run
|
||||
# - From the repo root: `python docs/examples/full_page_ocr.py`.
|
||||
# - The script prints Markdown text to stdout.
|
||||
#
|
||||
# Choosing an OCR backend
|
||||
# - Uncomment one `ocr_options = ...` line below. Exactly one should be active.
|
||||
# - `force_full_page_ocr=True` processes each page purely via OCR (often slower
|
||||
# than hybrid detection). Use when layout extraction is unreliable or the PDF
|
||||
# contains scanned pages.
|
||||
# - If you switch OCR backends, ensure the corresponding option class is imported,
|
||||
# e.g., `EasyOcrOptions`, `TesseractOcrOptions`, `OcrMacOptions`, `RapidOcrOptions`.
|
||||
#
|
||||
# Input document
|
||||
# - Defaults to `tests/data/pdf/2206.01062.pdf`. Change `input_doc_path` as needed.
|
||||
|
||||
# %%
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from docling.datamodel.base_models import InputFormat
|
||||
@@ -17,7 +45,8 @@ def main():
|
||||
pipeline_options.do_table_structure = True
|
||||
pipeline_options.table_structure_options.do_cell_matching = True
|
||||
|
||||
# Any of the OCR options can be used:EasyOcrOptions, TesseractOcrOptions, TesseractCliOcrOptions, OcrMacOptions(Mac only), RapidOcrOptions
|
||||
# Any of the OCR options can be used: EasyOcrOptions, TesseractOcrOptions,
|
||||
# TesseractCliOcrOptions, OcrMacOptions (macOS only), RapidOcrOptions
|
||||
# ocr_options = EasyOcrOptions(force_full_page_ocr=True)
|
||||
# ocr_options = TesseractOcrOptions(force_full_page_ocr=True)
|
||||
# ocr_options = OcrMacOptions(force_full_page_ocr=True)
|
||||
|
||||
Reference in New Issue
Block a user