简体   繁体   English

跨浏览器CSS用于打印

[英]Cross-browser CSS for printing

I thought this would be easier. 我认为这样会更容易。

A web app I am implementing must print some pages on a4 paper. 我正在实现的Web应用程序必须在a4纸上打印一些页面。 These pages are prepared just for being printed (they are not the same displayed in the 'app'), so I do not need to include in the same CSS different formats for various media types (they are different from the other pages, monochromatic, etc.): I just need to write one CSS style for the prints. 这些页面只是为打印而准备的(它们在“应用程序”中显示的不是相同的),因此我不需要在同一CSS中包含各种媒体类型的不同格式(它们与其他页面不同,单色,等):我只需要为打印编写一种CSS样式。

The basic CSS I am using is Bootstrap V3, from which I removed all the rules for the media type 'print'. 我使用的基本CSS是Bootstrap V3,从中我删除了媒体类型“ print”的所有规则。 I use a second CSS for overwriting some Bootstrap rules and no other files. 我使用第二个CSS来覆盖一些Bootstrap规则,而不覆盖其他文件。

The problem is this one: 问题是这个:

  • on the screen I see exactly the same page in Chrome and Safari; 在屏幕上,我在Chrome和Safari中看到的页面完全相同;
  • the printed results are completely different, especially for what concerns font size: Safari uses much smaller fonts. 打印的结果完全不同,尤其是在字体大小方面:Safari使用的字体要小得多。

Could you please suggest me a way to have the two browsers print the file in the same way? 您能建议我一种让两个浏览器以相同方式打印文件的方法吗?

Most debuggers allow you to debug in a specific media type. 大多数调试器允许您在特定的媒体类型中进行调试。 So for printing you can set the debugger to use CSS media = print to easily manipulate the styles as desired 因此,对于打印,您可以将调试器设置为使用CSS media = print以轻松地根据需要操纵样式

I've had similar issues in the past with some dt tables and I resolved it by adding an extra layer of css resets to my print stylesheet. 过去,我在某些dt表中也遇到过类似的问题,我通过在我的print样式表中添加了额外的CSS重置层来解决了该问题。

Anyway it sounds like you just need to explicitly define the font and font-size in your print css. 无论如何,听起来您只需要在打印CSS中明确定义字体和字体大小。

@media print {
    html, body {
       font: Arial;
       font-size: 12px;
    }
}

Its hard for me to suggest anything else without your tangibles but this is where I would start. 我很难在没有您的有形资产的情况下提出其他建议,但这就是我的出发点。

在此处输入图片说明

If you use Chrome and Safari for testing, you must check if you are using same printing engine for preview, because Chrome have built-in print enginge and to avoid that use CTRL+SHIFT+P shortcut. 如果您使用Chrome和Safari进行测试,则必须检查您是否使用相同的打印引擎进行预览,因为Chrome具有内置的打印引擎,并避免使用CTRL + SHIFT + P快捷键。 I had a lot of errors with Chrome built-in print engine. Chrome内置打印引擎存在很多错误。

Using a font-size in points for print will likely yield a more uniform result. 以磅为单位使用字体大小进行打印可能会产生更均匀的结果。 Pixels are for screens. 像素用于屏幕。 Points are a print unit of measure...font-size: 12pt; 点是度量的打印单位...字体大小:12pt;

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

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