Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set image on Header or Footer in Rotativa PDF

I need to insert some image on Header or Footer using Rotativa PDF.

I'm using C# MVC4 with Razor

I already tried: CustomSwitches = "--print-media-type --header-center \"text\""

like image 576
Otavio Alfenas Avatar asked Oct 01 '14 19:10

Otavio Alfenas


1 Answers

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.

like image 108
Charly Avatar answered Nov 06 '22 13:11

Charly