【问题标题】:wkhtmltopdf fails on Azure Websitewkhtmltopdf 在 Azure 网站上失败
【发布时间】:2013-01-20 01:03:00
【问题描述】:

我正在使用 https://github.com/codaxy/wkhtmltopdf 包装器从我网站上的网页创建一个 pdf(我传入一个绝对 URL,例如 http://mywebsite.azurewebsites.net/PageToRender.aspx 它在开发人员和另一个共享主机帐户中运行良好,但是当我部署到一个 Azure 网站失败了,我得到的只是一个 ThreadAbortException。 是否可以在 azure 上使用 wkhtmltopdf,如果可以,我做错了什么?

更新: 这个仅使用 Process.Start 的简单示例也不起作用。它只是在 Azure 上运行时挂起,但在其他服务器上运行良好。

string exePath = System.Web.HttpContext.Current.Server.MapPath("\\App_Data\\PdfGenerator\\wkhtmltopdf.exe");
string htmlPath = System.Web.HttpContext.Current.Server.MapPath("\\App_Data\\PdfGenerator\\Test.html");
string pdfPath = System.Web.HttpContext.Current.Server.MapPath("\\App_Data\\PdfGenerator\\Test.pdf");
StringBuilder error = new StringBuilder();
using (var process = new Process())
{
    using (Stream fs = new FileStream(pdfPath, FileMode.Create))
    {
        process.StartInfo.FileName = exePath;
        process.StartInfo.Arguments = string.Format("{0} -", htmlPath);
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.UseShellExecute = false;
        process.Start();
        while (!process.HasExited)
        {
            process.StandardOutput.BaseStream.CopyTo(fs);
        }
        process.WaitForExit();
    }
}

【问题讨论】:

  • 我们在 Windows 2012 Server 上运行的托管环境中运行 wkhtmltopdf 时遇到问题。如果有帮助,您可以阅读该页面在此pastebin 处吐出的错误
  • 你找到解决办法了吗?
  • 没有。看来您无法在 azure 网站上执行此操作。我们使用了在另一台主机上运行 wpf 服务的解决方法。

标签: azure wkhtmltopdf azure-web-app-service


【解决方案1】:

查看这个关于类似问题的 SO question。这家伙似乎已经得到了它的工作。 RotativaPDF 建立在 wkhtmltopdf 之上,因此建立了连接。我正在我们的 Azure 网站上亲自尝试 - 我将在不久的将来发布我的结果。

Azure and Rotativa PDF print for ASP.NET MVC3

【讨论】:

  • 我最终选择了一条不同的路线 - www.html2pdfrocket.com。这是一个您可以调用的 API,对我们非常有用。唯一的问题是我必须使用绝对 URL,这样他们的 API 才能找到页面的所有资源。这适用于 Azure,因为没有要添加到您的项目的引用。他们的网站上面有一些很好的例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-18
相关资源
最近更新 更多