Skip to content

Improve print output #680

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

Merged
merged 6 commits into from
May 1, 2018
Merged

Conversation

mattico
Copy link
Contributor

@mattico mattico commented Apr 27, 2018

Since #648, the content doesn't use left/padding-left to make room for the sidebar, instead using transform/margin-left. The print CSS wasn't updated for this change, so if the sidebar was visible it would push content to the right when printing.

@mattico
Copy link
Contributor Author

mattico commented Apr 27, 2018

Really need a checklist or something for making CSS changes.

@mattico mattico force-pushed the fix-print-sidebar branch from c50d166 to 6fbed87 Compare April 27, 2018 18:11
@mattico mattico changed the title Update print styles for new sidebar behavior Improve print output Apr 27, 2018
Browsers this old are already hilariously broken, so we don't need these fallbacks.
@Michael-F-Bryan
Copy link
Contributor

I tried running this on the user guide and got some pretty funny results. Using master everything gets pushed right by the sidebar, exactly as mentioned in the PR description.

master.pdf

But then when I tried saving the example book as PDF (via the print button) from the fix-print-sidebar branch the output went all funny and I don't think it contains the actual content any more.

with-sidebar-fix.pdf


Before

After

@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

@Michael-F-Bryan I can't reproduce that issue with either Chrome or Firefox and "Microsoft Print to PDF", can you give more specifics?

Chrome won't execute this if it's not marked as js
@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

Ah, OK. If I open the html in Chrome, I see the same issue. Doesn't happen with serve so probably another CORS issue.

@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

The issue doesn't happen in Firefox, and Chrome doesn't print any messages to the console. The print CSS doesn't reference any external files. I'm at a loss why this only happens on Chrome+Print+File and not any other situation...

@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

Unconditionally enabled the print CSS and the page renders fine, but the problem persists 😠.

@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

If I close the print dialog then Control+P again, it works fine. I think the issue is that in Chrome+File the page resources load quickly so DomContentLoaded fires before the page is completely finished rendering, or something.

@mattico
Copy link
Contributor Author

mattico commented Apr 29, 2018

Alright, adding a 100ms delay seems to solve the issue.

@mattico mattico force-pushed the fix-print-sidebar branch from 2033734 to 514615e Compare April 29, 2018 18:38
In certain situations Chrome willl fire window.onLoad before it's
done rendering. Add a 100ms delay to work around this.
@mattico mattico force-pushed the fix-print-sidebar branch from 514615e to ea88aec Compare April 29, 2018 18:41
@Michael-F-Bryan
Copy link
Contributor

@mattico I just checked out your latest changes and that seems to have fixed the issue. Chrome+File and Chrome+Serve is now rendering the print page correctly 🎉

@Michael-F-Bryan Michael-F-Bryan merged commit 69fef40 into rust-lang:master May 1, 2018
@mattico mattico deleted the fix-print-sidebar branch May 1, 2018 15:08
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
* Update print styles for new sidebar behavior

* Hide copy icons in print output

* Wait for mathjax rendering to complete before printing

* Remove old wrapping css
Browsers this old are already hilariously broken, so we don't need these fallbacks.

* Change mathjax script type
Chrome won't execute this if it's not marked as js

* Ensure page has rendered before printing
In certain situations Chrome willl fire window.onLoad before it's
done rendering. Add a 100ms delay to work around this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants