question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@media print (or @media not print) in Css ignored

See original GitHub issue

When using @media print and @media not print in the CSS in order to get rid of color, images … the generated pdf will ignore these.

On https://jsfiddle.net/wb2tgm6f/l the generated pdf still includes the

as visible text

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
cwallencommented, Feb 20, 2018

This isn’t printing, so the print media query won’t get triggered. The workaround I’ve used is through the css preprocessor I’m using, I duplicate the print styles on both @media print and body.print. Then I add the print class to the body right before triggering html2pdf, and then removing it right after.

10reactions
pietrogregorinicommented, Nov 9, 2019

Okay, forgot it… I had to run the removal of class after html2pdf function had completely run.

var source = document.getElementById('body');
source.classList.add('print');
html2pdf(source, {
     filename: 'Test.pdf',
     image: { type: 'jpeg', quality: 1 },
     html2canvas: { scale: 2 },
     jsPDF: { unit: 'mm', format: 'A4', orientation: 'landscape', putOnlyUsedFonts: true }
}).then(function(){
     source.classList.remove('print');
});

It’s not perfect (there’s a little subtle change in layout, of course) but whatever… 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS @media print not working at all
I'm struggling for hours now why the @media print is not working, I search on Google even on ...
Read more >
media print (or @media not print) in Css ignored · Issue #79
This isn't printing, so the print media query won't get triggered. The workaround I've used is through the css preprocessor I'm using, I ......
Read more >
media print for chrome not working
Have a value after a link that only shows when you print it? The code you have above has “content: none” (please, do...
Read more >
HTML & CSS Basics | Jan's Working with the Web
CSS lets you create different styles that apply only when printing. You can use two special style sections, @media print and @page.
Read more >
CSS: The Perfect Print Stylesheet | The Jotform Blog
Many areas of a website can't be printed. For one, they don't provide any relevant information, and for another, printing these areas is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found