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

SVG Image used as Logo is duplicated in PDF for every page #1978

Open
jsf84ksnf opened this issue Oct 5, 2023 · 3 comments
Open

SVG Image used as Logo is duplicated in PDF for every page #1978

jsf84ksnf opened this issue Oct 5, 2023 · 3 comments
Labels
performance Too slow renderings

Comments

@jsf84ksnf
Copy link

Cou can use an svg image as a logo ( @page { @top-right{ background-image: url("/static/logo.svg")}} ) and it works just fine.

But if the document has > 1 pages, the full SVG resource is included for every page in the pdfs, blowing up its size greatly. (100 pages includes the svg 100 times).

I also tried defining the logo as a svg-symbol with an id and then loading the id with svg-use, but that doesnt show up at all.

WeasyPrint Version: 60.1

@liZe liZe added the performance Too slow renderings label Oct 5, 2023
@liZe
Copy link
Member

liZe commented Oct 6, 2023

Hi!

Thanks for the report.

That’s right, when a SVG file is drawn multiple times, it’s included multiple times. That’s not the case for raster images, because a cache is used to avoid this, and we reference the PDF’s XObject each time the image is drawn. We should be able (hopefully) to store the drawing once in the PDF and reference it each time it’s required. But I don’t know yet which PDF structure to use for that.

@m-cisse-easy-live
Copy link

m-cisse-easy-live commented May 17, 2024

Hello @liZe ,

I am experiencing the same issue. I generate documents with icons using an SVG spritesheet. However, it seems that the entire SVG is loaded each time an icon is retrieved:

background-image: url("./spritesheet.svg");
background-repeat: no-repeat;
background-size: 20px 20px;

From reading this discussion thread, I understand that the SVG is reloaded every time, which can result in a PDF document size of 4 MB for 14 pages. If I remove the icons entirely, the file size can decrease to 770 KB.

Is there a planned update for WeasyPrint to address this issue?

Thank you in advance

@liZe
Copy link
Member

liZe commented May 17, 2024

Is there a planned update for WeasyPrint to address this issue?

There’s nothing planned for this issue.

If you (or anyone) is interested in solving this issue, the first step is to find in the PDF specification a way to store the drawing once and reference it multiple times.

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

3 participants