如何在Rotativa PDF中的页眉或页脚上设置图像

时间:2014-10-01 19:05:25

标签: asp.net-mvc pdf razor rotativa razorpdf

我需要使用Rotativa PDF在页眉或页脚上插入一些图像。

我正在使用带Razor的C#MVC4

我已经尝试过了: CustomSwitches =“ - print-media-type --header-center \”text \“”

1 个答案:

答案 0 :(得分:7)

如果您想在页眉/页脚中显示视图而不是文本,则可以将图像添加到视图中。

public ActionResult ViewPDF()
{
      string cusomtSwitches = string.Format("--print-media-type --allow {0} --footer-html {0}"
                Url.Action("Footer", "Document", new { area = ""}, "https"));


     return new ViewAsPdf("MyPDF.cshtml", model)
                {
                    FileName = "MyPDF.pdf",
                    CustomSwitches = customSwitches
                };
}

[AllowAnonymous]
public ActionResult Footer()
{
    return View();
}

不要忘记在页脚操作上添加[AllowAnonymous]属性,否则Rotatina无法访问该路径。