PDFToImageContent generates duplicate images for repeated page selections

Open Beginner friendly
#13,830 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start at _expand_page_range() in the PDF converter utilities and the PDFToImageContent component that calls it; reproduce with page_range=[1, 1] to see the duplicated image. Read the existing converter tests to see how page ranges are asserted, then confirm that the fix deduplicates pages while preserving the original selection order. Done looks like one image per unique page for repeated and overlapping ranges, with tests covering both cases.

Written by the indexing model from the issue text.

Description

P2

I noticed an issue with PDFToImageContent when the same PDF page is selected more than once.

For an example, selecting page 1 twice using page_range=[1, 1] generates two images of the same page instead of one.

Shows comparison of the output when selecting page 1 once and twice.
image

I also checked the expand_page_range() utility and noticed that it keeps duplicate page numbers when ranges overlap or the same page is specified multiple times.
image

I think each page should only be processed once while preserving the original selection order.

Could someone please confirm if this is the expected behaviour?
If not I'd be happy to work on a fix and add the necessary tests.

Dominant language
Python
Stars
27.1k
Forks
3.5k
Avg merge
1d 8h
Merged PRs (30d)
239

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from deepset-ai/haystack

All issues in deepset-ai/haystack

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.