问题描述
我想通过Rotativa库生成的PDF指定页眉和页脚。由于笔者回答应该使用CSS(中描述的)。不过,我没有能够做到这一点。
我在meta标签加载的样式表:
<链接HREF =print.css的rel =stylesheet属性类型=文/ CSS媒体=打印/>
和在底部的样式表:
@页{
@左上角 {
内容:最高机密;
颜色:红色
}
@右下角 {
内容:计数器(页);
字体样式:斜体
}
}
,然后生成PDF由:
公众的ActionResult ShowPdf()
{
VAR模型=新模式();
返回新ViewAsPdf(view.cshtml模型)
{
文件名=Report.pdf
CustomSwitches =--print-媒体类型
};
}
然后就没有出现在PDF的页眉和页脚。任何想法?
我已经发现了的的文档和它的存在说明如何管理页眉和页脚。
头中心文(或类似开关)的参数列表,这一切 -基本上你可以添加 所以,使用它与Rotativa这将是:。
公众的ActionResult ShowPdf()
{
VAR模型=新模式();
返回新ViewAsPdf(view.cshtml模型)
{
文件名=Report.pdf
CustomSwitches =--print-媒体类型--header中心\\文本\\
};
}
(我不知道,如果 - 打印介质类型
是必要的。)
I'm trying to specify headers and footers in a PDF generated by Rotativa library. As the author answered here it should be possible using CSS (described here). However, I'm not able to do this.
I have a stylesheet loaded in the meta tag:
<link href="print.css" rel="stylesheet" type="text/css" media="print" />
And in the stylesheet at the bottom:
@page {
@top-left {
content: "TOP SECRET";
color: red
}
@bottom-right {
content: counter(page);
font-style: italic
}
}
And then generating PDF by:
public ActionResult ShowPdf()
{
var model = new Model();
return new ViewAsPdf("view.cshtml", model)
{
FileName = "Report.pdf",
CustomSwitches = "--print-media-type"
};
}
And then nothing appears in the header and footer of the PDF. Any ideas?
I've found a documentation of wkhtmltopdf and it is described there how to manage headers and footers.
Basically you can just add --header-center "text"
(or similar switches) to the argument list and that's all.
So using it with Rotativa it would be:
public ActionResult ShowPdf()
{
var model = new Model();
return new ViewAsPdf("view.cshtml", model)
{
FileName = "Report.pdf",
CustomSwitches = "--print-media-type --header-center \"text\""
};
}
(I don't know if --print-media-type
is necessary.)
这篇关于显示页眉和页脚由Rotativa生成的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!