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

Graphics and colours not available for print #53

Open
royfrancis opened this issue Mar 11, 2016 · 3 comments
Open

Graphics and colours not available for print #53

royfrancis opened this issue Mar 11, 2016 · 3 comments

Comments

@royfrancis
Copy link

I noticed that if the html page with formattable is printed in chrome, the graphics and colours are not retained.

img

@marceluk
Copy link

I see the same problem in Firefox - is there a workaround for this issue?

marcel_uk

@mubashirqasim
Copy link

I am having the same issue as well. Please let me know when there is a workaround available...

@royfrancis
Copy link
Author

After digging into this for a bit, I have come to realize that this is not much to do with formattable. This is a general html/css issue and it gets complicated.

When handling html pages with css styles, colours for screen are separated from colours for print. Colours for print are in a media tag.

For example;

/* heading 1 color for screen */
h1 {
   color: #fff;
   background: url(banner.jpg);
}

/* heading 1 color for print */
@media print {
   h1 {
      color: #000;
      background: none;
   }

This makes sense since you usually don't want to print all the background colours and graphics. There are some solutions to force colours in print. One way is to change the css tags inside @media to same as screen or whatever you want.

Another solution often suggested especially for chrome is to include the following css:

body {
  -webkit-print-color-adjust: exact;
}

to be added to the css style document or into the rmarkdown document directly.

I have not been able to get either of them to work correctly. This also depends on where (what source) your css styles are coming from. In my case, working in RStudio RMarkdown, I know that my css styles are coming from a bootstrap style. For example; Bootswatch Flatly. If you go into the css style and search for media, you will see something like this:

@media print {
  *,
  *:before,
  *:after {
    background: transparent !important;
    color: #000 !important;
    -webkit-box-shadow: none !important;
            box-shadow: none !important;
    text-shadow: none !important;
  }

Notice the !important after the property style. This makes it harder to override that style with a css style defined in your rmarkdown document for example. And I think that might be the reason why the previously mentioned approaches did not work.

As I said before, it turned out to be more complicated than I thought. I reckon one potential solution would be to download the css style, modify the @media section and load it locally in rmarkdown through YAML as shown here. I haven't tried this out yet. If something works, please post here.

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

No branches or pull requests

3 participants