docling-project / docling-project/docling
Why I'm not getting text from the image inside the PDF, and instead getting image tag
- Dominant language
- Python
- Stars
- 66.4k
- Forks
- 4.8k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 95
Description
### Question
setup_mime_types()
input_paths = [
# Path("documents_folder/README.md"),
# Path("documents_folder/wiki_duck.html"),
# Path("documents_folder/word_sample.docx"),
# Path("documents_folder/lorem_ipsum.docx"),
# Path("documents_folder/powerpoint_sample.pptx"),
# Path("documents_folder/2305.03393v1-pg9-img.png"),
# Path("documents_folder/AlexandriaObol.pdf"),
Path("documents_folder/OCRdocument.pdf"),
# Path("documents_folder/Def Stops (Analysis) - Final 2(DEF Routing Analysis 08-12).csv"),
# Path("documents_folder/test_01.asciidoc"),
# Path("documents_folder/csv-comma.csv")
]
# Configure optimized PDF pipeline options
pdf_pipeline_options = PdfPipelineOptions(ocr_options=EasyOcrOptions(force_full_page_ocr=True))
pdf_pipeline_options.do_ocr = True
pdf_pipeline_options.do_table_structure = True
pdf_pipeline_options.table_structure_options.do_cell_matching = True
pdf_pipeline_options.generate_page_images = True
pdf_pipeline_options.images_scale = 2.0 # Increase for better OCR on small text
pdf_pipeline_options.generate_page_images = True
pdf_pipeline_options.generate_parsed_pages = True
pdf_pipeline_options.do_formula_enrichment = True
pdf_pipeline_options.do_code_enrichment = True
pdf_pipeline_options.ocr_options.force_full_page_ocr = True
pdf_pipeline_options.accelerator_options = AcceleratorOptions(
num_threads=4,
device=AcceleratorDevice.AUTO
)
doc_converter = (
DocumentConverter(
allowed_formats=[
InputFormat.PDF,
InputFormat.IMAGE,
InputFormat.DOCX,
InputFormat.HTML,
InputFormat.PPTX,
InputFormat.XLSX,
InputFormat.ASCIIDOC,
InputFormat.CSV,
InputFormat.MD,
],
format_options={
InputFormat.PDF: PdfFormatOption(
pipeline_cls=StandardPdfPipeline,
backend=PyPdfiumDocumentBackend,
pipeline_options=pdf_pipeline_options # Add optimized options only for PDF
),
InputFormat.DOCX: WordFormatOption(
pipeline_cls=SimplePipeline
),
InputFormat.IMAGE: ImageFormatOption(
pipeline_cls=StandardPdfPipeline,
backend=PyPdfiumDocumentBackend,
pipeline_options=pdf_pipeline_options
),
},
)
)
out_path = Path("docling_explorations/scratch")
# Create the output directory if it doesn't exist
out_path.mkdir(parents=True, exist_ok=True)
for input_path in input_paths:
print(f"\nProcessing: {input_path.name}")
start_time = time.time()
# Convert single file and measure its conversion time
conv_result = doc_converter.convert(input_path)
# Export to markdown format
markdown_file = out_path / f"{input_path.stem}.md"
with markdown_file.open("w", encoding="utf-8") as fp:
fp.write(conv_result.document.export_to_markdown())
end_time = time.time()
conversion_time = end_time - start_time
print(
f"Document: {input_path.name}"
f"\nConversion time: {conversion_time:.2f} seconds"
f"\nSaved markdown to: {markdown_file}\n"
)
if __name__ == "__main__":
main()
...
Output:
Note: RapidOCR() gives very poor results and when using latest models, it takes a lot of time
Contributor guide
Research direction
Reproduce the issue with OCRdocument.pdf using the shown DocumentConverter and PdfPipelineOptions configuration. Start by tracing StandardPdfPipeline through convert() and export_to_markdown(); done means explaining or correcting why the OCR output becomes an image tag instead of extracted text, with the expected result verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100