Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
548 views
Welcome To Ask or Share your Answers For Others

1 Answer

I've found a documentation of wkhtmltopdf (or a better archived version) 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:

public ActionResult ShowPdf()
{
     var model = new Model();
     return new ViewAsPdf("view.cshtml", model)
                {
                    FileName = "Report.pdf",
                    CustomSwitches = "--print-media-type --header-center "text""
                };
}

(I don't know if --print-media-type is necessary.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...