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

Inconsistent image extraction from image-only PDFs #155

Open
Cozokim opened this issue Sep 27, 2024 · 3 comments
Open

Inconsistent image extraction from image-only PDFs #155

Cozokim opened this issue Sep 27, 2024 · 3 comments

Comments

@Cozokim
Copy link

Cozokim commented Sep 27, 2024

First of all, I'd like to mention that pymupdf4llm works very well for most use cases. I'm using the to_markdown function, which performs exactly as expected. Great work!

However, I've encountered an issue with PDFs that contain only images (though I am not entirely sure if this issue is directly related to the fact that the PDFs consist solely of images). In these cases, some images are missing from the output. Additionally, when an image contains text, instead of extracting the image as a whole, the library splits the image into multiple smaller images, each containing only one word.

Problems observed:

  1. Some images are not extracted even tho i've put the image_size_limit to a very low value
  2. In cases where an image contains text, instead of extracting it as a single image, multiple small images are created, each containing a
    single word.

I am unsure whether there is a way to merge these smaller images into one or if this behavior is caused by pymupdf4llm or the PDF format itself, which I understand can be quite complex to handle.

I am using write_images = True and have tried lowering the image_size_limit to a very small value, but this did not resolve the issue.

Thanks for your help,
Cozokim

@JorjMcKie
Copy link
Contributor

Please provide a reproducer.

@Cozokim
Copy link
Author

Cozokim commented Sep 27, 2024

Sure, on this PDF for example, some of the images extracted are going to be only isolated words, and the right text from the third page is also missing : first_three_pages_full_images.pdf

I'm using :

pdf = "data\pdf\first_three_pages_full_images.pdf"
doc = fitz.open(pdf)
md_text = to_markdown(doc, write_images=True,image_size_limit=0.001)

@kalani9uggalle
Copy link

kalani9uggalle commented Oct 30, 2024

i'm having the same issue when extracting pdfs only with images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants