Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong text bounding boxes from the pdf parser #813

Open
petrgronat opened this issue Jan 27, 2025 · 1 comment
Open

Wrong text bounding boxes from the pdf parser #813

petrgronat opened this issue Jan 27, 2025 · 1 comment
Assignees
Labels
bug Something isn't working PDF parsing

Comments

@petrgronat
Copy link

Bug

For some PDFs (see attached samples), the BaseOcrModel.get_ocr_rects() method gets wrong bounding boxes. Whel I look at the bounding box, it looks like a vertical strip crossing the text in the middle of the line (see attached screenshot from EasyOcrMode.__call__() high_res_image.show() ).

As a result (on exo_pg1.pdf), the markdown is a pile of garbage. On the other hand, when I created very similar slide in google doc and exported to pdf (see exo_synth.pdf) the document is parsed normally.
...

exo_pg1.pdf
exo_synth.pdf

Image

Steps to reproduce

from docling.datamodel.pipeline_options import PdfPipelineOptions, EasyOcrOptions, OcrEngine
from docling.document_converter import DocumentConverter, PdfFormatOption, InputFormat
from pathlib import Path
filename_pdf = Path("~/exo_pg1.pdf")

# 1. Configure your OCR options
ocr_options = EasyOcrOptions(
    lang=["en"],            # list of language codes (EasyOCR or Tesseract)
)

# 2. Configure your PDF pipeline options
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.ocr_options = ocr_options  # attach your OCR config here

# Additional pipeline options (table structure, scaling, etc.)
pipeline_options.do_table_structure = True
pipeline_options.generate_page_images = True
pipeline_options.generate_picture_images = True
# ... etc.

# 3. Pass these pipeline options into the PdfFormatOption
doc_converter = DocumentConverter(
    format_options={
        InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
    }
)

# 4. Run the conversion
conv_res = doc_converter.convert(filename_pdf)
doc = conv_res.document
md = doc.export_to_markdown()
print(md)

Docling version

docling==2.15.1
docling-core==2.15.1
docling-ibm-models==3.2.1
docling-parse==3.1.1

Python version

Python 3.12.8

@petrgronat petrgronat added the bug Something isn't working label Jan 27, 2025
@PeterStaar-IBM PeterStaar-IBM self-assigned this Jan 28, 2025
@PeterStaar-IBM
Copy link
Contributor

@petrgronat Thanks, we will have a look at it asap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PDF parsing
Projects
None yet
Development

No branches or pull requests

2 participants