【问题标题】:NReco PDFGenerator fails on Azure Service FabricNReco PDFGenerator 在 Azure Service Fabric 上失败
【发布时间】:2017-04-09 01:33:34
【问题描述】:

我目前正在开发托管在 Azure 服务结构中的打印服务(一种将取代 Web 和辅助角色的新产品)。我使用 wkhtmltopdf 和 NReco.PDFGenerator.LT 作为其包装器,它在本地开发集群中运行良好,但在联机时失败。

我得到的唯一例外是Exception thrown: 'System.Exception' in NReco.PdfGenerator.LT.dll,我发现它很难调试,因为它不能说明什么是失败的。

阅读this 我在想集群上可能缺少一些东西,但是本地环境应该是在线环境的副本。此外,我在切换之前在同一集群中使用了带有 NReco 包装器的 phantomjs到 wkhtmltopdf 并且它在在线和本地都可以工作,我相信他们都使用相同的核心引擎(尽管不同的 fork)?

这是我的代码,在远程调试时我检查了许可证、.exe 路径和文件的值是否正确。

[HttpGet]
    public ActionResult Get(string target)
    {
        var wktohtmlPath = Path.Combine(_hostingEnvironment.WebRootPath, "lib");
        var htmlToPdf = new HtmlToPdfConverter() {
            Quiet = false,
            CustomWkHtmlArgs = "--print-media-type",
            PdfToolPath = wktohtmlPath,
            Margins = new PageMargins() { Left = 17, Right = 17, Top = 17, Bottom = 17 }
        };
        htmlToPdf.License.SetLicenseKey(
             _optionsAccessor.Value.LicenceOwner,
             _optionsAccessor.Value.LicenceKey
        );

        try
        {
            var fileBytes = htmlToPdf.GeneratePdfFromFile(target, null);
            var fileStream = new MemoryStream(fileBytes);
            return new FileStreamResult(fileStream, "application/pdf");
        }
        catch
        {
            return BadRequest();
        }
    }

感谢您的回答

【问题讨论】:

    标签: c# wkhtmltopdf azure-service-fabric nreco


    【解决方案1】:

    记录:有两个问题

    • 在线集群上缺少 C++ 运行时库(msvcp120.dll 和 msvcr120.dll)(感谢 NReco);
    • Service Fabric 似乎只能运行 x86 版本,而我使用的是 x64 版本。

    【讨论】:

      猜你喜欢
      • 2015-11-18
      • 1970-01-01
      • 2017-03-03
      • 2018-04-10
      • 2015-12-24
      • 2015-07-27
      • 2019-11-30
      • 2019-03-15
      • 1970-01-01
      相关资源
      最近更新 更多