Page.get_images_info() is returning empty array. Need a reliable way to detect non-text PDF pages #5021
Replies: 11 comments
|
This discrepancy as such is no bug. What appears to be text on that page in reality are vector graphics that mimic text. Identifying them as "picture" therefore is at least not far from the truth. One could argue that mimicked text should be OCR-ed ... and this is indeed what is built into the page analyzer module. If you run |
|
Also note that |
|
Hi @JorjMcKie and @julian-smith-artifex-com, Thanks for the quick reply. As you mentioned, OCR has been disabled for performance reasons, but that does not solve my issue. I will change title slightly My core logic is roughly: if hasImage(page): # in this method, i check page.get_image_infos() and check the image size (to ignore banners)
use pymupdf4llm.to_markdown(doc, pages=[page.number], ignore_images=True, use_ocr=False)
else:
process entire page as imageFrom what i understand, my current logic only detects images. I need a way to identify all non-text PDF pages, including pages that use vector graphics to render text-like content. so could you please share a code snippet that I can use to reliably detect non-text PDF page? |
|
Your "bug" example: is this a non-text page for you? |
|
Please correct me if I am wrong, but |
All right then: simply do |
|
That would solve for this particular PDF. However, as I mentioned above, my core logic (with a minor correction) needs to be more generic. I need a reliable way to determine whether a page contains images or vector graphics that visually represent text, so that I can process such pages differently from pages containing extractable text. I'll correct my non text page definition - page has text (optional) + (images or vector graphics that visually represent text) |
You are visiting the same points again: there is no way to determine this without OCR! |
|
Understood. Can I use an approach like this? If a page contains any block that occupies a significant portion of the page and is not classified as text or table, can I treat the entire page as an image page and process it? My apologies for prolonging this discussion, but this is very critical for us because we do not want to miss any extractable data from a page. |
If this is so you have only two options left:
The available OCR plugins for Tesseract and RapidOCR all perform what I call "hybrid OCR". They respect existing page text and only OCR the "rest" of the page. This works whether or not you are using the page analyzer. The result is a mixture of extractable text and text added by the OCR engine. |
|
For clarity, I am going to move this post to the "Discussions" tab. |
Uh oh!
There was an error while loading. Please reload this page.
Description of the bug
Hi Team,
i have page where
PFA pdf file.
Thanks of the support.
bug_page1.pdf
How to reproduce the bug
Run below python code
versions:
PyMuPDF 1.27.2.2
pymupdf-layout 1.27.2.2
pymupdf4llm 1.27.2.2
PyMuPDF version
1.27.2.2
Operating system
MacOS
Python version
3.14
All reactions