Skip to content

ENH: Add support for BrotliDecode filter (PDF 2.0) #3223 #3254

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

ash01ish
Copy link

Implements the BrotliDecode filter as specified in ISO 32000-2:2020, Section 7.4.11. Adds necessary constants, integrates the filter into the decoding logic, includes brotli as an optional dependency, adds unit tests, and updates documentation.

Closes #3223

@ash01ish ash01ish changed the title feat: Add support for BrotliDecode filter (PDF 2.0) #3223 ENH: Add support for BrotliDecode filter (PDF 2.0) #3223 Apr 13, 2025
Copy link

codecov bot commented Apr 13, 2025

Codecov Report

Attention: Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.69%. Comparing base (1c9eacd) to head (1016c29).

Files with missing lines Patch % Lines
pypdf/filters.py 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3254      +/-   ##
==========================================
- Coverage   96.71%   96.69%   -0.02%     
==========================================
  Files          53       53              
  Lines        9029     9048      +19     
  Branches     1674     1677       +3     
==========================================
+ Hits         8732     8749      +17     
- Misses        177      179       +2     
  Partials      120      120              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ash01ish ash01ish force-pushed the feat/add-brotli-decode branch 7 times, most recently from 1573164 to d339bc8 Compare April 14, 2025 02:15
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Is the official specification available in the meantime?

Apart from this, I have left some comments I stumbled upon during the review.

@ash01ish ash01ish force-pushed the feat/add-brotli-decode branch 2 times, most recently from 274ed94 to 4dd3fa0 Compare April 14, 2025 09:21
@ash01ish
Copy link
Author

Reverting the requirements.txt files to main will show an error that the package is not installed. Is there any other way to get them installed? - I have added them in dev.in and ci.in - expecting that the req will be generated while running the pipeline.

@ash01ish
Copy link
Author

Is the official specification available in the meantime?

The official specification for Brotli compression in PDF is not yet released. However, the PDF Association has announced its upcoming inclusion in PDF 2.0. Sample PDF files are available for developers to begin testing. https://pdfa.org/brotli-compression-coming-to-pdf/

@stefan6419846
Copy link
Collaborator

Reverting the requirements.txt files to main will show an error that the package is not installed. Is there any other way to get them installed? - I have added them in dev.in and ci.in - expecting that the req will be generated while running the pipeline.

You can change the .txt variants, but ONLY for the actual dependency.

@ash01ish ash01ish force-pushed the feat/add-brotli-decode branch from 8b4514f to b7a5245 Compare April 14, 2025 12:05
@ash01ish ash01ish force-pushed the feat/add-brotli-decode branch from 672f080 to a4fdd61 Compare April 14, 2025 15:18
@ash01ish ash01ish force-pushed the feat/add-brotli-decode branch from aee4bf8 to 3ba2235 Compare May 9, 2025 11:24
@ash01ish ash01ish requested a review from stefan6419846 May 9, 2025 13:37
@pytest.mark.skipif(importlib.util.find_spec("brotli") is None, reason="brotli library not installed")
def test_brotli_import_handling_available():
"""Verify brotli module is properly imported in pypdf.filters when available."""
# This test only runs when brotli is actually installed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is superfluous.


assert extracted_text.strip() == "Hello, Brotli!"

def test_brotli_import_error_with_patch():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not really understand why we need this complexity. Could you please elaborate?

@stefan6419846 stefan6419846 added the needs-change The PR/issue cannot be handled as issue and needs to be improved label Jun 5, 2025
@ash01ish ash01ish requested a review from stefan6419846 June 5, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-change The PR/issue cannot be handled as issue and needs to be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BrotliDecode filter
5 participants