NReco.PdfGenerator 服务器上的管道已结束错误

NReco.PdfGenerator The pipe has been ended error on the server

我正在为我的 PDF 文档使用 NReco.PdfGenerator(该组件基于 WkHtmlToPdf 工具),我的代码允许我创建一个 pdf 调用带有参数控制器、动作、模型的函数:

public static byte[] GeneratePdfDocument(System.Web.Mvc.Controller controller, string viewName, object model)
{
     string result;
     controller.ViewData.Model = model;
     using (StringWriter sw = new StringWriter())
     {
         ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
         ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
         viewResult.View.Render(viewContext, sw);

         result = sw.ToString();
     }

     return (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(result);
}

使用此代码,我可以根据我的视图轻松创建 PDF,它在我的开发环境中运行良好,但在服务器上出现此错误:

The pipe has been ended.

Description: An unhandled exception occurred during the execution of the    current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.IOException: The pipe has been ended.


[IOException: The pipe has been ended.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +11185413
System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count) +10770013
System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count) +139
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(String htmlFilePath, Byte[] inputBytes, String coverHtml, String outputPdfFilePath, Stream outputStream) +2166

[Exception: Cannot generate PDF: The pipe has been ended.]
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(String htmlFilePath, Byte[] inputBytes, String coverHtml, String outputPdfFilePath, Stream outputStream) +2734
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml, Stream output) +51
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml) +42

我认为这可能是我的 IIS 上的权限问题或某些配置问题,知道吗?

您可能缺少 适用于 VS2013 (x86) 的 Visual C++ 可再发行组件包。即使您的服务器是 运行 64 位 Windows,您也需要安装 x86 C++ 包。