简体   繁体   English

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

[英]how to set image on Header or Footer in Rotativa PDF

I need to insert some image on Header or Footer using Rotativa PDF. 我需要使用Rotativa PDF在页眉或页脚上插入一些图像。

I'm using C# MVC4 with Razor 我正在使用带有Razor的C#MVC4

I already tried: CustomSwitches = "--print-media-type --header-center \\"text\\"" 我已经尝试过:CustomSwitches =“ - print-media-type --header-center \\”text \\“”

If you wanted to display a View instead of text in the header/footer then you could add the image to the View. 如果要在页眉/页脚中显示视图而不是文本,则可以将图像添加到视图中。

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();
}

Don't forget to add the [AllowAnonymous] attribute on the Footer action otherwise Rotatina can't get access to the path. 不要忘记在Footer操作上添加[AllowAnonymous]属性,否则Rotatina无法访问路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM