Hi guys,
I have a problem with generating pdf report from ASP.NET Core app. I've followed this tutorial: https://jsreport.net/learn/dotnet-aspnetcore
Here is my code:
ExportController.cs
[MiddlewareFilter(typeof(JsReportPipeline))]
[Route("Export/ExportDataToPdf")]
public async Task<IActionResult> ExportDataToPdf()
{
HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf);
HttpContext.JsReportFeature().OnAfterRender((r) => {
using (var file = System.IO.File.Open("report.pdf", FileMode.Create))
{
r.Content.CopyTo(file);
}
r.Content.Seek(0, SeekOrigin.Begin);
});
return View();
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddSessionStateTempDataProvider();
services.AddSession();
services.AddMemoryCache();
//services.AddDistributedMemoryCache();
services.AddControllersWithViews()
.AddNewtonsoftJson();
services.AddJsReport(new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.Create());
}
Index.cshtml
<input class="button .button-block pull-right" type="submit" value="Export" onclick="location.href=' @Url.Action("ExportDataToPdf", "Export")'" />
After returning a view from ExportDataToPdf() I get blank pdf document in the browser. Looks like content was not placed to the stream. Any ideas what am I doing wrong?
Thanks