【问题标题】:Rotativa generating blank PDF in ServerRotativa 在服务器中生成空白 PDF
【发布时间】:2016-02-15 03:05:11
【问题描述】:

我们在 .Net MVC 5 项目中使用 Rotativa。它在本地像魅力一样工作,并且在部署到服务器时同样失败(生成空白 PDF)。但是,如果我登录到服务器并以 localhost 身份访问该网站,它会生成 PDF 就好了。

因此,它看起来像是运行应用程序池的权限问题。因此,出于测试目的,我更改为运行应用程序池以在“本地系统”上运行。还是同样的问题。

我们也试过:

  1. “查看PDF”
  2. 应用设置如下:<add key="WkhtmltopdfPath" value="<path to the folder>"/>

下面是代码:

return new ActionAsPdf("ActionMethod",new { id = id, partSelected =        part, selectedTab = selectedTab, isDownload = true })
{
    FileName = fileName,
    PageMargins = { Left = 0, Right = 0 },
    CustomSwitches = "--disable-external-links --disable-internal-links --disable-smart-shrinking --viewport-size 1600x900 --load-error-handling ignore",
    PageOrientation = Rotativa.Options.Orientation.Portrait,
    PageSize = Rotativa.Options.Size.A4,
    PageWidth = 210,
    PageHeight = 297
};

【问题讨论】:

  • 服务器有错误提示吗?

标签: asp.net-mvc pdf rotativa


【解决方案1】:

首先,您使用自定义开关 --load-error-handling ignore 禁用了显示错误。出于调试目的,暂时不禁用它可能会有所帮助。

其次,我的一个盲目猜测是,您可能有一些图像需要本地路径作为 pdf 上的 src?如果是这种情况,您将需要 @Server.MapPath 为每一个。

例如:

<img src="@Server.MapPath("your image path")"/>

【讨论】:

    【解决方案2】:
     var iResult = new Rotativa.ActionAsPdf("PrintForm", new { Id = Id }) { FileName = iFilename, SaveOnServerPath = ViewBag.FileName };
     iResult.UserName = System.Configuration.ConfigurationManager.AppSettings["ADUserID"].ToString();
     iResult.Password = System.Configuration.ConfigurationManager.AppSettings["ADPassword"].ToString();
     return iResult;
    

    这是一个代码示例,其中 aduser 是用户名和密码,请为此创建一个通用用户帐户..

    【讨论】:

      猜你喜欢
      • 2016-01-08
      • 2014-12-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 2012-09-13
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多