【问题标题】:Rotative CustomSwitches does not work旋转自定义开关不起作用
【发布时间】:2015-11-03 17:12:31
【问题描述】:

我在我的 MVC5 项目中使用 Rotativa.MVC 2.0.3。我在代码编辑器中不断收到错误消息,指出“ActionAsPDF 不包含 CustomSwitches 的定义”。我也尝试使用 ViewAsPDF,如下面的链接所示,结果相同。 以下是我发现的一些关于如何向 Rotativa PDF 添加页眉/页脚的资源:

CodeProject

CSharpCorner

我的控制器中的代码是:

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

所以问题是:如何在 Rotativa 2.0.3 中实现 CustomSwitches?或者,CustomSwitches 定义在哪里? PDF 在没有 CustomSwitches 标签的情况下呈现得非常好,所以我知道 Rotativa 正在做它的工作。

【问题讨论】:

    标签: asp.net-mvc-5 rotativa


    【解决方案1】:

    在寻找其他东西时,我偶然发现了this post,它回答了我的问题。

    基本上,我必须引用 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。希望这个答案对其他人有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2022-08-03
      • 1970-01-01
      • 2011-01-29
      相关资源
      最近更新 更多