0

I'm using Rotativa.MVC 2.0.3 in my MVC5 project. I keep getting an error in the code editor stating "ActionAsPDF does not contain a definition for CustomSwitches". I tried using ViewAsPDF as shown in the links below also, same result. Here are a couple of sources I found regarding how to add headers/footers to Rotativa PDFs:

CodeProject

CSharpCorner

The code in my controller is:

using Rotativa.MVC;

public ActionResult CertificatePDF(int? wo_nbr)
{
    var PDFresult = new ActionAsPdf("Certificate", new { wo_nbr = wo_nbr })
    {
        FileName = "Certificate.PDF",
        CustomSwitches = "fill in details later"
    };
    return PDFresult;
}

So the question is: How do I implement CustomSwitches in Rotativa 2.0.3? Or, where is the CustomSwitches definition? The PDF renders terrifically without the CustomSwitches tag, so I know Rotativa is doing it's job.

4

1 回答 1

1

在寻找其他东西时,我偶然发现了这篇回答我问题的帖子。

基本上,我必须引用 Rotativa.Core 并创建一个 DriverOptions 对象。

这是工作代码的样子:

using Rotativa.MVC;
using Rotativa.Core;

        public ActionResult CertificatePDF(int? wo_nbr)
        {
            string CustomSwitch = "--footer-line --footer-font-size \"8\" --footer-left \"Printed: \"" + DateTime.Now.Date.ToString("yyyy-MM-dd");
            var rotativaOptions = new DriverOptions() { CustomSwitches = CustomSwitch };
            var PDFresult = new ActionAsPdf("Certificate", new { wo_nbr = wo_nbr })
            {
                 RotativaOptions = rotativaOptions
            };
            return PDFresult;
        }

同样,我使用的是 Rotativa 2.0.3。希望这个答案对其他人有帮助!

于 2015-11-04T19:18:36.417 回答