我正在尝试在 Rotativa 库生成的 PDF 中指定页眉和页脚。正如作者在这里回答的那样,应该可以使用 CSS(在此处描述)。但是,我无法做到这一点。
我在元标记中加载了一个样式表:
<link href="print.css" rel="stylesheet" type="text/css" media="print" />
在底部的样式表中:
@page {
@top-left {
content: "TOP SECRET";
color: red
}
@bottom-right {
content: counter(page);
font-style: italic
}
}
然后通过以下方式生成 PDF:
public ActionResult ShowPdf()
{
var model = new Model();
return new ViewAsPdf("view.cshtml", model)
{
FileName = "Report.pdf",
CustomSwitches = "--print-media-type"
};
}
然后 PDF 的页眉和页脚中没有任何内容。有任何想法吗?