安装了本地,二进制和aspnetcore的nuget软件包。
将此代码添加到Statup.cs中的ConfigureServices:
var localWebServerReportingService = new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.Configure(cfg => cfg
.AllowedLocalFilesAccess()
.FileSystemStore()
.BaseUrlAsWorkingDirectory()
)
.AsWebServer()
.Create();
localWebServerReportingService.StartAsync();
services.AddJsReport(localWebServerReportingService);
以下是呈现文件的代码:
try
{
var viewHtml = await JsReportMvcService.RenderViewToStringAsync(HttpContext, RouteData, "InvoicePdf/InvoicePdf", invoiceGenerationModel);
var report = await JsReportMvcService.RenderAsync(new RenderRequest
{
Template = new Template
{
Recipe = Recipe.ChromePdf,
Engine = Engine.None,
Content = viewHtml,
Chrome = new Chrome
{
Format = "Letter",
MarginTop = "0.5in",
MarginBottom = "0.5in",
MarginLeft = "0.5in",
MarginRight = "0.5in"
}
}
});
var memoryStream = new MemoryStream();
await report.Content.CopyToAsync(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
catch (Exception e)
{
_logger.LogError("Error generating pdf file!");
_logger.LogError(e.Message);
return null;
}
在我的开发机器上,它工作正常。在IIS上,我收到此错误:
“无法呈现模板。超时错误:30000毫秒后pdf生成未完成”
我还尝试将以下内容添加到第一块,但没有帮助:
.RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport"))
有什么想法吗?