-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
File Size Increase from pypdf==3.8.1 to pypdf==3.9.0 when watermarking #1897
Comments
@MartinThoma |
@Lucas-C For the
How should I write to a BytesIO stream instead? Would it maybe be possible to point users directly to what they should use instead? |
@pubpub-zz I've added the minimal example in the top :-) |
Calling |
I just tried to find other files that show the same issue:
|
I confirm your analysis. |
This might be a useful test: @pytest.mark.samples()
@pytest.mark.slow()
#@pytest.mark.xfail(reason="Issue 1897")
def test_compression():
def create_stamp_pdf() -> BytesIO:
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica", "B", 16)
pdf.cell(40, 10, "Hello World!")
byte_string = pdf.output()
return BytesIO(byte_string)
template = PdfReader(create_stamp_pdf())
template_page = template.pages[0]
reader = PdfReader(SAMPLE_ROOT / "009-pdflatex-geotopo/GeoTopo.pdf")
writer = PdfWriter()
for page in reader.pages:
page.merge_page(template_page)
writer.add_page(page)
for page in writer.pages:
page.compress_content_streams()
b = BytesIO()
writer.write(b)
b.seek(0)
output_data = len(b.read())
assert output_data < 6 * 10**6 with |
@pubpub-zz I think I will make a release with this fix today. I've just updated the first post with a "Issue Summary". I think I will do the same for all new issues. This way it is easier for people to see if/how long they were affected. |
I've noticed that the watermarking process in my job suddenly produces way bigger PDFs. In a specific example with this PDF file I've noticed:
pypdf==3.8.1
produces a 3.7 MB filepypdf==3.9.0
produces a 5.2 MB fileI'm not sure if the issue is with 3.8.1 or with 3.9.0.
Code
Issue summary
pypdf>=3.9.0, pypdf<=3.10.0
The text was updated successfully, but these errors were encountered: