Skip to content

Add tagged PDF and PNG predictor samples, document 017 - #45

Merged
MartinThoma merged 1 commit into
mainfrom
add-tagged-and-png-predictor-samples
Oct 30, 2026
Merged

MartinThoma merged 1 commit into
mainfrom
add-tagged-and-png-predictor-samples

Conversation

@MartinThoma

Copy link
Copy Markdown
Member
  • 030-tagged-pdf: a tagged PDF 2.0 file with a hand-written structure tree, and the script that creates it.
  • 031-png-predictors: an RGB image with 8 bits per component, stored once without a predictor and once with /Predictor 15, using the PNG filters None, Sub, Up, Average and Paeth in bands of 50 rows. Both images must decode to the same data.
  • 032-png-predictors-low-bit-depth: the same for grayscale images with 1, 2 and 4 bits per component, where the Sub, Average and Paeth filters use the byte to the left.
  • 017-unreadable-meta-data: a README explaining the deliberate damage of the file and why its entry in files.json cannot be checked.

* 030-tagged-pdf: a tagged PDF 2.0 file with a hand-written structure
  tree, and the script that creates it.
* 031-png-predictors: an RGB image with 8 bits per component, stored
  once without a predictor and once with /Predictor 15, using the PNG
  filters None, Sub, Up, Average and Paeth in bands of 50 rows. Both
  images must decode to the same data.
* 032-png-predictors-low-bit-depth: the same for grayscale images with
  1, 2 and 4 bits per component, where the Sub, Average and Paeth
  filters use the byte to the left.
* 017-unreadable-meta-data: a README explaining the deliberate damage
  of the file and why its entry in files.json cannot be checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartinThoma
MartinThoma merged commit 80d67b9 into main Oct 30, 2026
2 checks passed
@MartinThoma
MartinThoma deleted the add-tagged-and-png-predictor-samples branch October 30, 2026 06:06
MartinThoma added a commit to py-pdf/pypdf that referenced this pull request Oct 30, 2026
Update the sample files to py-pdf/sample-files#45, which adds
031-png-predictors and 032-png-predictors-low-bit-depth. Each page of
these files shows the same image twice: once without a predictor, and
once with /Predictor 15, using the PNG filters None, Sub, Up, Average
and Paeth in bands of 50 rows. Both images must decode to the same data.

The 8-bit RGB image of 031-png-predictors does. The grayscale images
of 032-png-predictors-low-bit-depth, with 1, 2 and 4 bits per
component, do not: for fewer than 8 bits per pixel, the bytes per pixel
used by the Sub, Average and Paeth filters are rounded down to 0 instead
of up to 1. These cases are marked as strict xfail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stefan6419846

Copy link
Copy Markdown
Collaborator

Which PDF/UA standard does the tagged PDF file target? According to veraPDF, neither PDF/UA-1 nor PDF/UA-2 are met by the file.

@MartinThoma

Copy link
Copy Markdown
Member Author

It doesn't target any standard. I simply wanted to have a PDF with some tags so that we could start adding support for tagged PDFs :-)

Having an example file that follows one of the standards would be ideal, though 👍

stefan6419846 pushed a commit to py-pdf/pypdf that referenced this pull request Oct 30, 2026
)

* TST: Compare PNG predicted images with images without a predictor

Update the sample files to py-pdf/sample-files#45, which adds
031-png-predictors and 032-png-predictors-low-bit-depth. Each page of
these files shows the same image twice: once without a predictor, and
once with /Predictor 15, using the PNG filters None, Sub, Up, Average
and Paeth in bands of 50 rows. Both images must decode to the same data.

The 8-bit RGB image of 031-png-predictors does. The grayscale images
of 032-png-predictors-low-bit-depth, with 1, 2 and 4 bits per
component, do not: for fewer than 8 bits per pixel, the bytes per pixel
used by the Sub, Average and Paeth filters are rounded down to 0 instead
of up to 1. These cases are marked as strict xfail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* TST: Make xfail strict by default

With xfail_strict, a test marked as xfail that passes makes the test
run fail, so that marks of fixed issues do not stay behind.

test_issue_2336 is the only test that passed unexpectedly. The
whitespace issue #2336 was fixed by d5233a0 "BUG: Improve handling of
spaces in text extraction (#2882)" in October 2024, so its xfail mark is
removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* TST: Correct outdated and wrong expectations of image tests

* test_get_images: imagemagick-lzw.pdf was marked as xfail for "broken
  image extraction" since #1330. The image is extracted correctly, but
  as Im0.tiff: images using the LZW filter are saved as TIFF since that
  PR. Expect Im0.tiff and remove the mark, and the commented-out mark of
  imagemagick-ASCII85Decode.pdf.
* test_4bits_image: the reference PNG was extracted with pypdf (#3761)
  and is black, like the image pypdf extracts. The 16 x 16 /DeviceGray
  image is a gradient, with the gray level y in each pixel of row y, as
  poppler renders it. Compare with this gradient instead, and mark the
  test as xfail, as 4-bit /DeviceGray images are extracted as black
  palette images.
* Refer to #4308 in the xfail reason of the PNG predictor tests with
  fewer than 8 bits per pixel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* TST: Refer to #4316 in the xfail reason of test_4bits_image

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

2 participants