mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-31 14:34:40 +00:00
chore(examples): Add example how to force OCR
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
This commit is contained in:
parent
dea1d91ebe
commit
1963e7145b
43
docs/examples/full_page_ocr.py
Normal file
43
docs/examples/full_page_ocr.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from docling.backend.docling_parse_backend import DoclingParseDocumentBackend
|
||||||
|
from docling.datamodel.base_models import InputFormat
|
||||||
|
from docling.datamodel.pipeline_options import (
|
||||||
|
EasyOcrOptions,
|
||||||
|
PdfPipelineOptions,
|
||||||
|
TesseractCliOcrOptions,
|
||||||
|
TesseractOcrOptions,
|
||||||
|
)
|
||||||
|
from docling.document_converter import DocumentConverter, PdfFormatOption
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
input_doc = Path("./tests/data/2206.01062.pdf")
|
||||||
|
|
||||||
|
pipeline_options = PdfPipelineOptions()
|
||||||
|
pipeline_options.do_ocr = True
|
||||||
|
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
|
||||||
|
# ocr_options = EasyOcrOptions(force_full_page_ocr=True)
|
||||||
|
# ocr_options = TesseractOcrOptions(force_full_page_ocr=True)
|
||||||
|
ocr_options = TesseractCliOcrOptions(force_full_page_ocr=True)
|
||||||
|
pipeline_options.ocr_options = ocr_options
|
||||||
|
|
||||||
|
converter = DocumentConverter(
|
||||||
|
format_options={
|
||||||
|
InputFormat.PDF: PdfFormatOption(
|
||||||
|
pipeline_options=pipeline_options,
|
||||||
|
backend=DoclingParseDocumentBackend,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
doc = converter.convert(input_doc).document
|
||||||
|
md = doc.export_to_markdown()
|
||||||
|
print(md)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user