Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Print Preview doesn't load @media only print font-face

I would like a different font-face for print than for screen. Unfortunately Google Chrome Print Preview (works on other browsers) won't load the font-face and won't show the text. But if you try it a second time, the font-face is loaded and then, Google Chrome Print Preview will show the text!

Here is a fiddle on which you can reproduce the problem. (nb: on the fiddle the font url does not exist, but at least the preview should show the text as 'serif').

Is there a better solution than forcing the pre-loading of the print font-face for all @media?

The problems occurs on all versions of Google Chrome <= 53.

I used this code:

@media only print {
    @font-face {
        font-family: "Computer Modern";
        src: url('/fonts/cm/cmunrm.otf');
        font-weight: normal;
        font-style: normal;
    }

    body {
        font-family: "Computer Modern", serif;
    }
}

https://jsfiddle.net/72bsf1n0/

like image 720
Vincent J Avatar asked Sep 07 '16 07:09

Vincent J


People also ask

How do I turn on Print preview in Google Chrome?

Or, use a keyboard shortcut: Windows & Linux: Ctrl + p. Mac: ⌘ + p.

How do you inspect element in Print preview?

As of Chrome 48+, you can access the print preview via the following steps: Open dev tools – Ctrl/Cmd + Shift + I or right click on the page and choose 'Inspect'. Hit Esc to open the additional drawer.

How to fix loading print preview take long time issue in chrome?

Follow below solution steps to resolve loading print preview take long time issue by disabling print preview function in Google Chrome. Step 1: Open regedit. Step 2: Go to Computer\HKEY_CURRENT_USER\SOFTWARE\Policies\Google\Chrome or Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome

How to disable print preview in Google Chrome?

Step 1: Open regedit. Step 2: Go to Computer\HKEY_CURRENT_USER\SOFTWARE\Policies\Google\Chrome or Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome Step 3: Add DisablePrintPreview REG_DWORD with value 1. Step 4: Restart Google Chrome. Remark: You can use the group policy to push down this key to all user PC. Step 1: Open Terminal.

Why can’t I print on my Chromebook?

If your Chromebook can’t load the print preview, restart your laptop, printer, and router. Additionally, remove and set up the printer again. If the issue persists, clear your Chrome cache, and disable your extensions. You can also reset your browser to default settings.

Does @media print work with chrome or Firefox?

@media print worked for firefox and when I tried using chrome it is a mess. Lots mentioned use @media screen and (-webkit-min-device-pixel-ratio:0) which I did and chrome doesn’t read all selector and the properties. for example I have @media screen and (-webkit-min-device-pixel-ratio:0) { a [href]:after { content: none !important; } }


2 Answers

Just found this question via Google after we had just experienced the same problem. Sad to see 11 months gone by with no answer, so perhaps this will help you and others.

Chrome seems to load the custom font 'on-demand'. So, if the font isn't already used on the page, your first 'Print Preview' fails to have it yet, subsequent ones will have it. Likely a timing issue there.

One solution would be to make sure you also use the print font on the regular version of the page.

@font-face {
  font-family: "Computer Modern";
  src: url('/fonts/cm/cmunrm.otf');
  font-weight: normal;
  font-style: normal;
}

@media only print {
    body {
        font-family: "Computer Modern", serif;
    }
}

.printfont {
    font-family: "Computer Modern", serif;
}

https://jsfiddle.net/72bsf1n0/8/

like image 180
Dreamwing Avatar answered Sep 26 '22 03:09

Dreamwing


There is a issue for this here https://bugs.chromium.org/p/chromium/issues/detail?id=284840

For now you need to sure there is printed font rendered before using print and you render at least 1 character from every language group you want to print:

  • Cyrillic (Supported by Open Sans)
  • Cyrillic Extended (Supported by Open Sans)
  • Greek (Supported by Open Sans)
  • Greek Extended (Supported by Open Sans)
  • Latin (Supported by all Fonts)
  • Latin Extended (Supported by Open Sans)
  • Vietnamese (Supported by Open Sans)

For now I add characters from Latin extended

<div class="chrome-font-fix">sš<b>sš</b><i>sš</i></div>

with invisible style

.chrome-font-fix {
    position: absolute;
    visibility: hidden;
}
like image 41
PaDi Avatar answered Sep 25 '22 03:09

PaDi