简体   繁体   English

使用Open Sans字体时,Chrome无法在首次打印时正确打印

[英]Chrome Not Printing Correctly On First Print When Using Open Sans Font

Updated Question 更新的问题

So, I've found what's causing this issue. 所以,我发现了造成这个问题的原因。 It is, in fact, open sans as suggested in this question . 事实上,正如这个问题所建议的那样,它是开放式的。 Now my question is, why is Chrome not loading the first time when using Open Sans? 现在我的问题是,为什么Chrome在第一次使用Open Sans时没有加载?

Here's what I'm seeing. 这就是我所看到的。 Open Sans is included directly in the project. Open Sans直接包含在项目中。 Instead of the import statement like in the question above, we have a number of @font-face css rules such as this one: 我们有许多@font-face css规则,而不是上面这个问题中的import语句,而不是像以下那样:

@font-face {
    font-family:'Open Sans';
    font-style:normal;
    fontweight:300;
    src:url('../fonts/OpenSans-Light-webfont.eot');
    src:url('../fonts/OpenSans-Light-webfont.eot?#iefix')
    format('embedded-opentype'), url('../fonts/OpenSans-Light-webfont.woff')
    format('woff'), url('../fonts/OpenSans-Light-webfont.ttf')
    format('truetype'), url('../fonts/OpenSans-Light-webfont.svg#open_sanslight')    
    format('svg')
}

If I comment those out, the <h3> tags I use load fine. 如果我评论这些,我使用的<h3>标签加载正常。 If I leave those in, they don't load the first time but do load every subsequent time. 如果我留下这些,他们不会第一次加载,但每次都会加载。 Has anyone else using Open Sans seen this issue? 有没有其他人使用Open Sans看过这个问题? How did you fix it? 你怎么修好它的?


Original Question 原始问题

I'm stumped on an issue with Google Chrome and printing. 我对谷歌浏览器和打印问题感到困惑。 There are a few specific elements that are missing when opening print for the first time. 第一次打开打印时,有一些特定元素缺失。 Each time after that first time everything loads fine. 每次在第一次之后,一切都很好。 It's like the CSS rules didn't quite finish processing before the print preview renders. 就像CSS规则在打印预览渲染之前没有完成处理。

The page is using Bootstrap 3 along with some custom styles. 该页面使用Bootstrap 3以及一些自定义样式。 The HTML for the element in question is as follows: 有问题的元素的HTML如下:

<h3 class="myHide">Some text</h3>

The screen/normal CSS is as follows: 屏幕/普通CSS如下:

.myHide { display: none !important; }

The print CSS is as follows: 打印CSS如下:

.myHide { display: block !important; }

Unfortunately I cannot share the actual CSS and HTML, but the above is identical in function. 不幸的是我不能分享实际的CSS和HTML,但上面的功能相同。 The first time I hit print, every <h3> with that class doesn't show up but there is blank space where it should be. 我第一次点击打印时,该类的每个<h3>都没有显示,但是应该有空白区域。 Every time I hit print after that it shows fine. 每次我打印后都表现得很好。 I'm only seeing this issue in Chrome. 我只在Chrome中看到此问题。 FF and IE work fine every time no matter how I print. 无论我如何打印,FF和IE每次都能正常工作。

I've tried a few things which were mainly small tweaks to the CSS. 我尝试了一些主要是对CSS的小调整。 One thing I tried was switching from the custom class to show/hide stuff to the ones offered in Bootstrap, but the same behavior was observed. 我试过的一件事是从自定义类切换到显示/隐藏Bootstrap中提供的东西,但观察到相同的行为。 I've spent quite a while googling solutions, trialing different options, and talking with others about this, but haven't found a working solution yet which leads me here hoping someone out there has seen this. 我花了很长时间谷歌搜索解决方案,试验不同的选项,并与他人谈论这个,但还没有找到一个有效的解决方案,这导致我在这里希望有人看到这一点。

Note: I've looked at a similar question but fonts aren't imported like that for this project so that solution won't work (unless it's an issue with Open Sans itself and not an issue with how it's imported into the project). 注意:我看过一个类似的问题,但字体不是像这个项目那样导入的,所以解决方案不起作用(除非它是Open Sans本身的问题,而不是它如何导入项目的问题)。

Update : The page does have some functions listening for the print event. 更新 :页面确实有一些函数正在侦听打印事件。 Specifically, I use onbeforeprint and onafterprint for FF and IE and I use matchMedia for Chrome. 具体来说,我使用onbeforeprintonafterprint for FF和IE,我使用matchMedia for Chrome。 I'm still looking into them, but it seems unreasonable that these would be delaying the processing for CSS styles and HTML elements on the first time but not subsequent times. 我仍然在研究它们,但这些在第一次延迟CSS样式和HTML元素的处理而不是后续时间似乎是不合理的。 However, I'll keep looking into it. 但是,我会继续研究它。

Ended up just changing the styles used. 结束只是改变使用的样式。 Instead of using display: none I'm now using the following: 而不是使用display: none我现在使用以下内容:

.my-hide {
  display: block !important;
  height: 0px;
  overflow: hidden;
}
@media print {
  .my-hide {
    height: auto;
  }
}

For some reason these CSS rules get processed in time while the others don't. 出于某种原因,这些CSS规则会及时处理,而其他规则则不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM