简体   繁体   English

如何从window.print()隐藏或修改标题?

[英]How to hide or modify header from window.print()?

I created a view which look like a PDF document. 我创建了一个看起来像PDF文档的视图。 Now I want to print it using window.print() , but when I run this code it generates header and footer. 现在,我想使用window.print()打印它,但是当我运行此代码时,它将生成页眉和页脚。

I change the footer using this code: 我使用以下代码更改页脚:

let footer = "Nr"+this.contractForm.contract_number+this.datePipe.transform(this.contractForm.date, 'd.MM.yyyy');

window.history.pushState("object or string", "Title", footer.replace("http://", ""));

I want to remove header (it generates date and (I think) title). 我想删除标题(它生成日期和(我认为)标题)。

I tried to use remove header and footer from window print 我试图从窗口打印中使用删除页眉和页脚

And many similar solutions. 和许多类似的解决方案。

Summarizing, I want to remove header from generated file. 总而言之,我想从生成的文件中删除标头。

You can use CSS rules for this (or SCSS, if you wish). 您可以为此使用CSS规则(如果需要,也可以使用SCSS)。

Here is an example where I hide the .hideme class. 这是我隐藏.hideme类的示例。 You can click the print button to see it in action. 您可以单击print按钮以查看其操作。

 .hideme { border: 5px solid black; height: 100px; } .showme { border: 5px dotted black; height: 100px; } @media print { .hideme { display: none; } } 
 <div class="hideme"> Will be hidden </div> <div class="showme"> Will be shown </div> <button onclick="print()"> Print </button> 

I've also created an example in StackBlitz using SCSS and Angular if you want to see that in action. 如果您想看到实际效果,我还使用SCSS和Angular在StackBlitz中创建了一个示例。

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

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