【发布时间】:2020-11-11 22:16:44
【问题描述】:
我有一个内置在 ASP.NET Webforms VB.NET 中的 Web 应用程序。我正在创建一种利用 WKHTMLTOPDF 和 NReco PDF Generator 库通过 url 导出页面的方法。
在我的本地开发过程中,除了奇怪的“进程已在使用”之外,当我重新启动我的电脑并且之前什至没有执行任何操作时,一切似乎都正常。
当我将网站上传到我们的服务器时,PDF 库似乎永远无法工作,我遇到了一个不太明显的错误。当我尝试将任何页面导出为任何内容,甚至将文本导出为 pdf 时,我会在我们的日志中看到:
Inner Exception Type: NReco.PdfGenerator.WkHtmlToPdfException
Inner Exception: Exit with code 1, due to unknown error. (exit code: 1)
Inner Source: NReco.PdfGenerator
Inner Stack Trace:
at NReco.PdfGenerator.HtmlToPdfConverter.CheckExitCode(Int32 exitCode, String lastErrLine, Boolean outputNotEmpty)
at NReco.PdfGenerator.HtmlToPdfConverter.InvokeWkHtmlToPdf(PdfSettings pdfSettings, String inputContent, Stream outputStream)
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
Exception Type: System.Exception
Exception: Cannot generate PDF: Exit with code 1, due to unknown error. (exit code: 1)
Source: Exporting
Stack Trace:
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml, String outputPdfFilePath)
at PROJECT.Export.DownloadFiles(List`1 list) in C:\Users\NAME\source\repos\PROJECT\Export.aspx.vb:line 252.
我已经确保项目包含所有相关文件,我什至在服务器和开发机器上都安装了 WKHTMLTOPDF。利用 CMD,我可以生成任何 PDF,但在我的应用程序中,它似乎总是在我们的实时生产服务器上失败。
我生成 PDF 的代码非常简单:
If check = True Then
Try
'Generate PDF
'htmlToPdf.GeneratePdfFromFile(exp.URL, Nothing, "..\" & pathURL)
htmlToPdf.GeneratePdf("<h3> TEST PDF </h3> ", Nothing, "..\" & pathURL)
'Set download
download = True
'Catch exception, log it
Catch ex As Exception
ExceptionUtility.LogException(ex, "Exporting")
End Try
End If
谁能提供任何关于我如何克服这个问题的见解?我昨天花了一整天的时间在论坛上搜索,但没有找到解决方案!
非常感谢任何帮助。
【问题讨论】:
-
这看起来像一个类似的问题 - 你检查了吗? stackoverflow.com/questions/52980828/…
-
我将尝试安装任何丢失的 C++ 文件,然后重试!
-
仅供参考我在服务器上的当前文件在图像中:imgur.com/a/jQE4vVQ。
-
另外,我不确定,如果这些文件不存在,wkhtmltopdf 是否可以通过服务器上的命令行工作?我可以通过 CMD 生成 PDF,但不能通过托管的 Web 应用程序。
-
@Homungus 我设法安装了所有丢失的文件,但不幸的是我没有发现任何变化。正如我所怀疑的,当我的本地版本完美运行时,wkhtmltopdf 通过命令行工作,而不是通过我的托管站点。
标签: asp.net vb.net pdf wkhtmltopdf nreco