Repository navigation
Replies: 2 comments 1 reply
|
Thanks for opening this discussion. It seems like the title is incorrect, as we are talking about the
Regarding your actual remarks:
In general, having missing features added to pypdf itself is desirable, especially when there are relevant decoding parameters to consider. My main issue with the currently proposed code is that we would have 23 KiB and/or 1000 lines of own code to maintain afterwards "just" to support one "simple" parameter, while having to understand the internals of CCITT Group 4/TIFF files as well - with all its possible quirks. I am a bit unsure about the benefits versus the maintenance costs for this, due to as far as I understand, there is no easy way to have some existing library do this.
From our test files, it seems like the |
|
I agree: the implementation as it stands is pretty dodgy and nowhere close to understandable or supportable. If it can't be made so, it's definitely not worth it, but seeing as you've indicated interest in the functionality itself, I think I'll take a bit of time to understand just what in the hell Claude has done here to see how much fluff could be eliminated from reuse of existing pypdf features and/or simplification of the implementation itself. More to come. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
The tiff header trick pypdf uses to 'decode' data compressed with the /CCITTFaxDecode filter back into a tiff image does not support the /EncodedByteAlign parameter shown below:
Example
Using python 3.10.6 on Windows with pypdf v6.5.0 and pillow v11.3.0
Inputs
byte_aligned_tiff.pdf
normal_tiff.pdf
Tests
Outputs
Byte Aligned ❌
byte_aligned_image.tiff

byte_aligned_data.tiff
Standard ✅
normal_image.tiff

normal_data.tiff
Proposal
Implement a native python /CCITTFaxDecode decompression algorithm and use it if and only if the /EncodedByteAlign parameter is true and the /K parameter is -1 indicating CCITT Group 4 compression.
Proof of Concept
The prototype module below is a crude proof of concept written mostly by Claude.
If there's sufficient interest, I'll work on cleaning it up, integrating it into the existing decoding / image workflow, and submitting a PR.
Prototype Module
ccitt_g4_decoder.py
Usage
Outputs
Byte Aligned ✅
byte_aligned_decoded.tiff

Standard ✅
normal_decoded.tiff

Next Steps
Confirm the prototype's behavior on a broader sample set. If other community members have access to PDFs that use /EncodedByteAlign with the /CCITTFaxDecode filter or know a means to produce such PDFs from image inputs, please reach out.
All reactions