[英]Printing Html Document formatted with CSS
I have a asp.net mvc application and my Views are in HTML5. 我有一个asp.net mvc应用程序,我的视图使用HTML5。 I need to print a view as a report. 我需要将视图打印为报告。 This View shows some data with <table/>
tag and it is formatted with css style as font-family
, font-size
, text-align
properties etc. When I try to print it with Chrome (exporting to PDF) my css does not work, I mean, the print's result is shown without formating. 此视图显示带有<table/>
标记的数据,并使用CSS样式将其格式化为font-family
, font-size
, text-align
属性等。当我尝试使用Chrome打印(导出为PDF)时,我的CSS没有我的意思是,打印结果显示时未格式化。
What can I do to solve this problem? 我该怎么做才能解决这个问题? It Does not matter whether I use css to apply the style or use html tags to format the page, but I wish it would leave the impression formatted. 我使用css来应用样式还是使用html标签来格式化页面都没有关系,但是我希望它能使印象保持格式化。
PS: I would like to keep the html valid document. PS:我想保留html有效文档。
You need to split up the css for screen and print separately just by following setting 您只需按照以下设置将css拆分为屏幕并单独打印
<link href="css/main.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/print.css" media="print" rel="stylesheet" type="text/css" />
then no need to change your html code just change the css or duplicate the old css. 那么无需更改您的html代码,只需更改CSS或复制旧的CSS。
You can try to define the css semantics with @media print
rule, then stylize the stylesheet with that in mind. 您可以尝试使用@media print
规则定义css语义,然后牢记样式表的样式。 Maybe this help. 也许有帮助。
You can use different styles for screen and print media in your style sheet, ie 您可以在样式表中为屏幕和打印介质使用不同的样式,即
@media screen
{
table.test {
font-family:"Times New Roman",Georgia;
font-size:10px;
// more
}
}
@media print
{
table.test {
font-family:Verdana, Arial;
font-size:10px;
// more
}
}
When you'll print the table only styles defined in print media will be applied. 当您打印表格时,将仅应用在打印介质中定义的样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.