jsReport generates blank pdf



  • 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



  • Could you please try this example? Does it work for you?
    https://github.com/jsreport/jsreport-dotnet-example-webapp

    I don't know what you have in the ExportDataToPdf view. Maybe there is a problem.
    I could take a look if you would create a minimal public repo that shows the problem.



  • Yes, your example is working.

    I had wrong view attached to the ExportDataToPdf function (I thought that it creates stream from current opened view).
    Now it's partially working, but chart is missing. Check out images bellow. Chart is produced through javascript library Google.Charts. In the html code is showing as svg image.

    this is an app:
    1_1616438737627_dashboard1.PNG

    this is a pdf output:
    0_1616438737624_dashboard.PNG

    Have you seen something similar to this issue?
    I can't post entire code to the repo, because I don't own rights.

    Thank you.



  • The reason can be that the pdf is being printed before the chart finished its rendering.
    This can be solved by delaying printing until you have everything loaded and rendered.
    Please see the documentation and example
    https://jsreport.net/learn/chrome-pdf#printing-triggers
    https://playground.jsreport.net/w/admin/O3R9I~xl


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.