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" />
And in the stylesheet at the bottom:
@page {
@top-left {
content: "TOP SECRET";
color: red
}
@bottom-right {
content: counter(page);
font-style: italic
}
}
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"
};
}
And then nothing appears in the header and footer of the PDF. Any ideas?
If you wanted to display a View instead of text in the header/footer then you can do so like this:
Don't forget to add the [AllowAnonymous] attribute on the Footer action otherwise Rotatina can't get access to the path.
try it it will work 100 %
}
I've found a documentation of wkhtmltopdf and it is described there how to manage headers and footers.
Basically you can just add
--header-center "text"
(or similar switches) to the argument list and that's all.So using it with Rotativa it would be:
(I don't know if
--print-media-type
is necessary.)Here is how I did it (in full):