Skip to content
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

PDF file size almost double in v53 #1414

Closed
hildogjr opened this issue Aug 2, 2021 · 4 comments
Closed

PDF file size almost double in v53 #1414

hildogjr opened this issue Aug 2, 2021 · 4 comments
Labels
performance Too slow renderings
Milestone

Comments

@hildogjr
Copy link

hildogjr commented Aug 2, 2021

I am reporting a issue that is affecting my migrating from WeasyPrint 52.5 to 53.0, as part of the issues on #1412 (fix on #1413): the PDF file almost double the size by using the bellow configurations on a report template example:

# On weasyprint 52.5
font_config = weasyprint.fonts.FontConfiguration()
report_css = [weasyprint.CSS(filename=resource_path_join('report.css'), font_config=font_config)]
printer.write_pdf(file_name_report,
                  stylesheets=report_css,
                  font_config=font_config,
                  optimize_images=True,  # Optimize the image size (resolution into the PDF?).
                  presentational_hints=True)  # Follow the image aspects given into the HTML.

Found in https://hildogjr.gitlab.io/unicamp-electric-inventory/ (28.5MB)

# On weasyprint 53.0
font_config = weasyprint.text.fonts.FontConfiguration()
report_css = [weasyprint.CSS(filename=resource_path_join('report.css'), font_config=font_config)]
printer.write_pdf(file_name_report,
                  stylesheets=report_css,
                  font_config=font_config,
                  optimize_size=('fonts', 'images',)
                  presentational_hints=True)  # Follow the image aspects given into the HTML.

(40.6MB) I could not attach the file.

@liZe
Copy link
Member

liZe commented Aug 2, 2021

Hello!

Could you please share your HTML, CSS and static files used to generate this document?

@liZe liZe added the performance Too slow renderings label Aug 2, 2021
@hildogjr
Copy link
Author

hildogjr commented Aug 2, 2021

The file to convert is the "Relatório.html" with all static files on "Temporary". It appear to be not related with the JPG files, bellow a comparative (+/- temporary folder images and weasyprint version):

ls Relatório* -l
-rw-rw-r-- 1 lab lab 28492964 ago  2 16:00 Relatório+images_v52.pdf
-rw-rw-r-- 1 lab lab  3097807 ago  2 18:05 Relatório--images_v52.pdf
-rw-rw-r-- 1 lab lab 40594437 ago  2 15:52 Relatório+images_v53.pdf
-rw-rw-r-- 1 lab lab 15406735 ago  2 17:54 Relatório--images_v53.pdf

Compiling without the "Temparary" images folder I got 3.1MB on v52.5 and 15.4MB on v53.0.

The file is a 7z compressed file, I had to change de extension to attach here.
Files for weasyprint.7z.txt

@liZe liZe closed this as completed in 694eddb Aug 3, 2021
@liZe
Copy link
Member

liZe commented Aug 3, 2021

The problem was caused by images not being deduplicated when they were included in patterns. In your case, the watermark displayed on each page was displayed as a pattern (because it’s a background), and the image was though embedded in the document for each page (+600 times).

Thanks a lot for the report and for your sample!

@liZe liZe added this to the 53.1 milestone Aug 3, 2021
@hildogjr
Copy link
Author

hildogjr commented Aug 3, 2021

Confirmed now a reduction of 211kB in the PDF file compared with v52.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Too slow renderings
Projects
None yet
Development

No branches or pull requests

2 participants