naturalcrit / homebrewery

Create authentic looking D&D homebrews using only markdown
https://homebrewery.naturalcrit.com
MIT License
1.08k stars 327 forks source link

Background images become unoptimized PNGs in PDFs #751

Open MrTumnus907 opened 6 years ago

MrTumnus907 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

That’s exactly what was happening. I’ve since broken it into separate documents.

This prevents linking pages in the table of contents but using a pdf merger I can still have a complete document. Still a great program I use all the time.

Thanks for the response.

On Nov 10, 2018, at 5:15 PM, Trevor Buckner notifications@github.com wrote:

Sorry I haven't replied in a while. I think @RKuerten https://github.com/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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/stolksdorf/homebrewery/issues/751#issuecomment-437635307, or mute the thread https://github.com/notifications/unsubscribe-auth/AnmufQW3h40Ne7aRYZipFA_9sIhy6zQoks5ut3pGgaJpZM4Wl1Jq.

calculuschild commented 5 years ago

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:

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 commented 3 years ago

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 commented 3 years ago

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