Skip to content

Commit 71376db

Browse files
committed
update req, pdf generation.
1 parent 4dd3fa0 commit 71376db

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

requirements/ci-3.11.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ typing-extensions==4.12.2
7575
# via
7676
# mypy
7777
# typeguard
78+
brotli==1.1.0
79+
# via -r requirements/ci.in

requirements/ci.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ typing-extensions==4.12.2
7777
# typeguard
7878
zipp==3.20.2
7979
# via importlib-metadata
80+
brotli==1.1.0
81+
# via -r requirements/ci.in

requirements/dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ zipp==3.20.2
8686
# The following packages are considered to be unsafe in a requirements file:
8787
# pip
8888
# setuptools
89+
brotli==1.1.0
90+
# via -r requirements/ci.in
Binary file not shown.
619 Bytes
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
"""
3+
Create a minimal PDF with Brotli compression for testing purposes.
4+
5+
This script generates a simple PDF file that uses Brotli compression
6+
for the content stream, allowing for testing of the BrotliDecode filter
7+
in pypdf.
8+
"""
9+
10+
import brotli
11+
import os
12+
13+
# Simple PDF structure with Brotli-compressed content stream
14+
# The content stream will contain a simple "Hello, Brotli!" text
15+
content_stream = b"BT /F1 24 Tf 100 700 Td (Hello, Brotli!) Tj ET"
16+
compressed_content = brotli.compress(content_stream, quality=5)
17+
18+
# PDF structure
19+
pdf = [
20+
b"%PDF-1.7\n",
21+
b"1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n",
22+
b"2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n",
23+
b"3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>\nendobj\n",
24+
b"4 0 obj\n<< /Length " + str(len(compressed_content)).encode() + b" /Filter /BrotliDecode >>\nstream\n" + compressed_content + b"\nendstream\nendobj\n",
25+
b"5 0 obj\n<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>\nendobj\n",
26+
b"xref\n0 6\n0000000000 65535 f \n0000000010 00000 n \n0000000060 00000 n \n0000000115 00000 n \n0000000234 00000 n \n" +
27+
(b"0000000" + str(334 + len(compressed_content)).encode() + b" 00000 n \n"),
28+
b"trailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n" + str(400 + len(compressed_content)).encode() + b"\n%%EOF"
29+
]
30+
31+
# Write PDF to file
32+
# Define paths relative to the script's location (resources/)
33+
script_dir = os.path.dirname(__file__)
34+
output_dir = os.path.join(script_dir, "brotli-test")
35+
output_path = os.path.join(output_dir, "brotli-compressed.pdf")
36+
37+
# Ensure the output directory exists
38+
os.makedirs(output_dir, exist_ok=True)
39+
with open(output_path, "wb") as f:
40+
for part in pdf:
41+
f.write(part)
42+
43+
print(f"Created test PDF with Brotli compression at: {output_path}")

tests/test_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def test_main_decode_brotli_installed():
821821
pytest.skip("brotli library not installed")
822822

823823
# Use the prototype PDF provided by PDF Association
824-
pdf_path = RESOURCE_ROOT / "brotli-test" / "Brotli-Prototype-PDFs" / "Brotli-Prototype-FileA.pdf"
824+
pdf_path = RESOURCE_ROOT / "brotli-test" / "brotli-compressed.pdf"
825825
if not pdf_path.exists():
826826
pytest.skip(f"Brotli test PDF not found at {pdf_path}")
827827

0 commit comments

Comments
 (0)