2025-01-26 08:07:56 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from docling.datamodel.base_models import InputFormat
|
|
|
|
from docling.datamodel.pipeline_options import (
|
|
|
|
PdfPipelineOptions,
|
|
|
|
TesseractCliOcrOptions,
|
|
|
|
TesseractOcrOptions,
|
|
|
|
)
|
|
|
|
from docling.document_converter import DocumentConverter, PdfFormatOption
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2025-02-07 08:43:31 +01:00
|
|
|
input_doc = Path("./tests/data/pdf/2206.01062.pdf")
|
2025-01-26 08:07:56 +01:00
|
|
|
|
|
|
|
# Set lang=["auto"] with a tesseract OCR engine: TesseractOcrOptions, TesseractCliOcrOptions
|
|
|
|
# ocr_options = TesseractOcrOptions(lang=["auto"])
|
|
|
|
ocr_options = TesseractCliOcrOptions(lang=["auto"])
|
|
|
|
|
|
|
|
pipeline_options = PdfPipelineOptions(
|
|
|
|
do_ocr=True, force_full_page_ocr=True, ocr_options=ocr_options
|
|
|
|
)
|
|
|
|
|
|
|
|
converter = DocumentConverter(
|
|
|
|
format_options={
|
|
|
|
InputFormat.PDF: PdfFormatOption(
|
|
|
|
pipeline_options=pipeline_options,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
doc = converter.convert(input_doc).document
|
|
|
|
md = doc.export_to_markdown()
|
|
|
|
print(md)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|