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

Background images become unoptimized PNGs in PDFs #751

Open
MrTumnus907 opened this issue Sep 12, 2018 · 11 comments
Open

Background images become unoptimized PNGs in PDFs #751

MrTumnus907 opened this issue Sep 12, 2018 · 11 comments
Labels
blocked Waiting on a dependency, other feature, etc., first 🅖 Chrome Bug Bug is in Chrome, not Homebrewery

Comments

@MrTumnus907
Copy link

I've been trying to export my homebrew for a while (96 pages) and each time it fails to work.
I followed the guidelines listed on the homepage and it still didn't work.
The closest I've gotten is a saved file on my desktop which "won't open because the file is empty"

The normal message from Chrome is simply "printer failed check your settings and try again" and if it's opened in Safari the program just bogs down and does nothing.

Please help. I'd really like an offline version of my work.

@calculuschild
Copy link
Member

Two things:

  1. The homebrewery is only supported on Google Chrome. If you haven't already, try using Chrome.

  2. If you provide a share link to your document, as was requested in the issue report template, we can have someone look at your document and see if we can figure out what is causing your issue.

@MrTumnus907
Copy link
Author

I've only been using Chrome. Tried safari simply to see if that would change anything (it was worse so there's that).

Share link:
http://homebrewery.naturalcrit.com/share/SySt3Q6aWm

@MrTumnus907
Copy link
Author

When using Chrome to print. The destination is set to "Save as PDF" page size to "Letter" and "background Graphics" is enabled. Clicking the save button causes the page to crash after a few moments.

@RKuerten
Copy link
Collaborator

I'm facing a similar issue, using Chrome and et cetera. Looks like the Save as PDF cannot handle larger brews anymore. I have exported to PDF a +200 page before, but right now, I can't export a book of 140 pages I made.

Not a big issue, as I can break the brew in smaller ones and merge then with ilovepdf.com, but would be nice if someone finds a way for to make it work again.

@calculuschild
Copy link
Member

Sorry I haven't replied in a while. I think @RKuerten is right. It may be an issue with large documents. For now, I would recommend following his solution of breaking the document into smaller parts, but we also noticed that the PDFs generated by the Homebrewery tend to be rather large. There may be some bloat we can get rid of to make it work better.

@MrTumnus907
Copy link
Author

MrTumnus907 commented Nov 11, 2018 via email

@calculuschild calculuschild changed the title Export to PDF not functioning Export to PDF fails with large documents Nov 12, 2018
@calculuschild
Copy link
Member

calculuschild commented Nov 12, 2018

Looking into this a little more, apparently there is a bug with Chrome and the way it handles background images when printing PDFs. Any other image using an <img> tag, it will copy over directly, but for some reason it converts the background image into an unoptimized PNG which becomes 2-10x larger. I have a workaround that is pretty ugly that essentially puts the background as a separate image instead of using the CSS background:

<style>
  .phb{ background : white;}
  .phb:before {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: -1;
  	content: url(https://i.imgur.com/77CNx8a.jpg);
  }
</style>

This seems to cut down the PDF size to about 1/3 for entirely blank documents with just background, and the PDF generates much more quickly. I don't plan to keep that imgur link up indefinitely though, so don't count on that code working forever.

Any thoughts on this method?

@Gazook89
Copy link
Collaborator

For what it's worth, I tried the original linked example here just now, from Chrome macOS, and had no issue printing to pdf besides just taking awhile to load. Was able to save it just fine.

Not sure if the chrome bug @calculuschild is still an issue, but I don't see anything wrong with using :before except it is a little obtuse (even if necessary).

@calculuschild
Copy link
Member

calculuschild commented Sep 13, 2021

The original bug from Chrome was here: https://bugs.chromium.org/p/chromium/issues/detail?id=801430.

Looks like this was solved back in April 2018, but we were still noticing the bug after that according to the date of my post above.

Just tested it and the issue still exists. 20 empty pages (background only) is ~11.6 MB. Replacing background-image with a normal image cuts it to ~3.2 MB.

20 pages - Background-image.pdf
20 pages - Fixed.pdf

On further inspection, it looks like there is a remaining bug in Chrome that it is converting background-images into unoptimized PNGs if they are clipped in any way (overflow is hidden).

Relevant Chrome issues here. Star them to bring more attention:
https://bugs.chromium.org/p/chromium/issues/detail?id=910588
https://bugs.chromium.org/p/chromium/issues/detail?id=897732

@calculuschild calculuschild changed the title Export to PDF fails with large documents Background images become unoptimized PNGs in PDFs Sep 13, 2021
@calculuschild calculuschild added the blocked Waiting on a dependency, other feature, etc., first label Dec 22, 2021
@calculuschild calculuschild added the 🅖 Chrome Bug Bug is in Chrome, not Homebrewery label Apr 11, 2022
@Gazook89
Copy link
Collaborator

Just noting here that the current Chrome Canary has a fix for this. https://issues.chromium.org/issues/40759668#comment14

@calculuschild
Copy link
Member

Just noting here that the current Chrome Canary has a fix for this. https://issues.chromium.org/issues/40759668#comment14

I think this Chrome update is for duplicate images, not unoptimized bitmaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting on a dependency, other feature, etc., first 🅖 Chrome Bug Bug is in Chrome, not Homebrewery
Projects
None yet
Development

No branches or pull requests

4 participants