在 Rotativa 生成的 PDF 中显示页眉和页脚 [英] Displaying headers and footers in a PDF generated by Rotativa

查看:24
本文介绍了在 Rotativa 生成的 PDF 中显示页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rotativa 库生成的 PDF 中指定页眉和页脚.正如作者在此处所回答的那样,应该可以使用 CSS(描述 此处).但是,我无法做到这一点.

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" />

在底部的样式表中:

@page {
    @top-left {
        content: "TOP SECRET";
        color: red
    }
    @bottom-right {
        content: counter(page);
        font-style: italic
    }
}

然后通过以下方式生成PDF:

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"
                };
}

然后在 PDF 的页眉和页脚中什么也没有出现.有什么想法吗?

And then nothing appears in the header and footer of the PDF. Any ideas?

推荐答案

我找到了一个 文档wkhtmltopdf(或更好的存档版本),并在那里描述了如何管理页眉和页脚.

I've found a documentation of wkhtmltopdf (or a better archived version) and it is described there how to manage headers and footers.

基本上,您只需将 --header-center "text"(或类似的开关)添加到参数列表中即可.

Basically you can just add --header-center "text" (or similar switches) to the argument list and that's all.

因此将它与 Rotativa 一起使用将是:

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""
                };
}

(不知道是否需要--print-media-type.)

这篇关于在 Rotativa 生成的 PDF 中显示页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆