简体   繁体   English

如何找到纸张尺寸/可打印尺寸并在打印时设置页眉和页脚?

[英]How to find a paper size / printable size and set the header and footer on print?

This is some what difficult me. 这让我有些困难。 My client require to print the data's with header and footer on each page. 我的客户需要在每页上打印带有页眉和页脚的数据。

There is a chance to use a A4, A3, A5 and Landscape papers. 有机会使用A4, A3, A5Landscape纸。 How can i able to set the header and footer on each of the page? 如何在每个页面上设置页眉和页脚?

And how can i able to set a data length according to the page? 以及如何根据页面设置数据长度? is there a way to create print template? 有没有办法创建打印模板?

I am using underscore-template in Backbone . 我在Backbone使用underscore-template

Any one suggest me a way please? 有人建议我一种方法吗?

For your issue no difference which template engine you use. 对于您的问题,使用哪种模板引擎没有区别。

For doing something with javascript before HTML Document has been printed you could use: 要在打印HTML文档之前使用javascript进行操作,可以使用:

For Firefox and InternetExplorer - window.onbeforeprint . 对于Firefox和InternetExplorer- window.onbeforeprint

Workaround for other browser - window.matchMedia('print') . 其他浏览器的解决方法-window.matchMedia('print')


The better way for having nice look when user tries to print page is to use CSS's media queries, which will apply particular rules when user want to print the HTML Document: 当用户尝试打印页面时,更好看的更好方法是使用CSS的媒体查询,当用户希望打印HTML文档时,它将应用特定的规则:

<link rel="stylesheet" media="print" href="print.css" />

or add media query to your css file: 或向您的CSS文件添加媒体查询:

@media screen {
   body {font-family:verdana, arial, sans-serif;} // this will apply to printed page
}

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

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