Asp.Net Core - Render multiple PDFs and download zip



  • Hi,

    please I'm struggling with the following scenario.
    I'm developing an ASP.NET Core 2.1 web app. I'm running jsreport as Utility (jsReport.Binary v.2.4.0, jsReport.AspNetCore 2.0.1, jsReport.Local 2.0.1).
    I can successfully render a single PDF report using razor views with multiple CSSs (bootstrap 3.3.7 included), and then let the client download it.
    What I want to achieve is to correctly generate multiple PDFs (e.g. using RenderViewAsync), include them in a zip file, and provide the zip file to the client for download (I don't want to persist the resulting zip file on the server machine).
    I can generate the PDFS with RenderViewAsync, include them in the zip file, and let the client download the zip file. The problem I'm facing is that none of the PDFs is correctly styled. None of the CSS files I'm referencing is applied to the PDF. Inline styling (in header and footer) is correclty rendered.
    How can I solve my problem?

    Thank you so much.



  • Hi,

    in the jsreport asp.net core middleware, we inject the base tag to your html so your local styles are downloaded.
    https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportFeature.cs#L28
    https://www.w3schools.com/tags/tag_base.asp

    If you use the RenderViewAsync, this is not set.
    https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMVCService.cs#L58
    This is probably something I missed. You need to do it explicitly now.

    renderRequest.Options.Base = $"{Context.Request.Scheme}://{Context.Request.Host}";
    


  • Hi,

    thank you for your suggestion.
    I was alerady trying to prepend the "base url" to my styles. I've now added that line of code in the initialization of my RenderViewAsync calls.
    I have a different problem now: all the text within the body of my PDFs is gone. I've debugged the issue, and the view appears correctly fed with the model data. The table styling I'm using (e.g. a gray bottom border for each table line) is printed, but no text in the body of my PDFs.

    The same razor views are correctly rendered as standalone PDFs.
    Please, do you have any other suggestion?

    Thank you so much.



  • Try to debug it and compare the RenderRequest instances. If both are the same, it needs to produce the same result.
    Put the breakpoints somewhere here
    https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMiddleware.cs#L49
    https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMVCService.cs#L60



  • Thank you for your suggestion.
    I'm using jsreport as nuget packages. How can I reach the sources for putting the breakpoints?

    Thank you so much.



  • I linked the sources already. You can clone it somewhere and I think just open the file in VS.
    If it won't work try to google out "how to debug third-party library in VS c#" or something like that.



  • Hi.
    Thank you for your suggestions.
    The problem was not related to jsreports itself, but with some weird CSS behaviour.
    I've simplified the CSS used in my reports, and jsreport started to work almost as expected again.

    The only thing I'm still struggling with is the @import directive within a CSS file. In particular, I'd like to import a specific font. No matter if use the @importdirective with local fonts or with remote ones, the report renders blank. This behavior is the same no matter if I use the jsreport middleware or the RenderViewAsync.
    Please, do you have any suggestion about font management?

    Thank you so much.



  • Fonts are sometimes tricky. Please try to share the simple html using that font in playground.
    https://playground.jsreport.net/



  • Hi. Thank you for your suggestion. It's not a priority for us at the moment, though I'll provide some sample as soon as possibile.
    We're facing another very specific issue. We've deployed the web app with the working jsreport reporting feature to a production server. That specific server is locally reachable via a local domain like https://<appname>.studio.local
    On that machine, none of the CSS is applied when we try to generate a PDF via jsreport. Please, what shoud we do to solve this problem? we have already tried to set the local domain in the Options.Base, without luck.
    The same version of our web app runs fine both locally and on a publicly reachable server.
    Thank you so much,
    best regards.



  • Try to render html recipe and check what exactly you have in the html base tag by viewing its source.
    Is the css then applied in the html? Can you reach the url in the base tag, after you remote login to the server?
    Maybe you need to use some kind of localhost or 127.0.0.1 instead.


Log in to reply
 

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