asp.net-mvc-4 – NReco.PdfGenerator服务器上的管道已经结束错误

我正在为我的PDF文档使用 NReco.PdfGenerator(该组件基于WkHtmlToPdf工具),我的代码允许我使用参数controller,action,model创建一个调用函数的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 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,Stream outputStream) +2734
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent,Stream output) +51
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent,String coverHtml) +42

我认为这可能是我的IIS上的权限或某些配置的问题,任何想法?

解决方法

您可能缺少VS2013(x86)的Visual C Redistributable Packages.即使您的服务器运行的是64位Windows,也需要安装x86 C软件包.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....