HELP Strategy Required in ASPNETCORE 2



  • I have a class that is being used as a strategy to convert HTML to PDF.

    public byte[] Execute(byte[] document, Dictionary<string, string> parameters)
    {
    try
    {
    var localReporting = new LocalReporting();

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    localReporting.UseBinary(jsreport.Binary.OSX.JsReportBinary.GetBinary());
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    localReporting.UseBinary(jsreport.Binary.OSX.JsReportBinary.GetBinary());
                } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    localReporting.UseBinary(jsreport.Binary.JsReportBinary.GetBinary()); 
                }
                         
                ILocalUtilityReportingService reportingService = localReporting.AsUtility().Create();
    
                var report = reportingService.RenderAsync(new RenderRequest()
                {
                    Template = new Template()
                    {
                        Recipe = Recipe.PhantomPdf,
                        Engine = Engine.None,
                        Content = Encoding.UTF8.GetString(document)
                    }
                });
                report.Wait();
    
                return report.Result.Content.ToByteArray();
            }
            catch(Exception ex)
            {
                return null;   
            }
        }
    

    When I call this Execute method, either from my controller action or via a console app I get the error message exception :

    {jsreport.Local.JsReportBinaryException: Error rendering report: at jsreport.Local.Internal.LocalUtilityReportingService.<RenderAsync>d__10.MoveNext()}

    I have added the NuGet packages; jsreport.aspnetcore, jsreport.Binary.Linux (& OSX, Windows), jsreport.Local. The intention is pass any HTML to the strategy and get a PDF returned.

    Appreciate any help and questions.



  • Full method code here:

    public byte[] Execute(byte[] document, Dictionary<string, string> parameters)
    {
    try
    {
    var localReporting = new LocalReporting();

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    localReporting.UseBinary(jsreport.Binary.OSX.JsReportBinary.GetBinary());
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    localReporting.UseBinary(jsreport.Binary.OSX.JsReportBinary.GetBinary());
                } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    localReporting.UseBinary(jsreport.Binary.JsReportBinary.GetBinary()); 
                }
                         
                ILocalUtilityReportingService reportingService = localReporting.AsUtility().Create();
    
                var report = reportingService.RenderAsync(new RenderRequest()
                {
                    Template = new Template()
                    {
                        Recipe = Recipe.PhantomPdf,
                        Engine = Engine.None,
                        Content = Encoding.UTF8.GetString(document)
                    }
                });
                report.Wait();
    
                return report.Result.Content.ToByteArray();
            }
            catch(Exception ex)
            {
                return null;   
            }
        }


  • Should add, I am running this in a docker container, linux based.



  • <h1>An unhandled exception occurred while processing the request.</h1>
    <div class="titleerror">AggregateException: One or more errors occurred. (Error rendering report: )</div>
    <p class="location">System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)</p>
    <div class="titleerror">JsReportBinaryException: Error rendering report: </div>
    <p class="location">jsreport.Local.Internal.LocalUtilityReportingService+<RenderAsync>d__10.MoveNext()</p>

    Even if I put HTML directly in the Content field the same error occurs. I have tried running it locally but I am using HighSierra and PhantomPdf throws errors. So have reverted back to the Docker container; and get the same error.



  • The exception should include output logs from jsreport. Please inspect this exception property.

    However looking at your code, I think you have very ugly copy and paste error there :)

    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    localReporting.UseBinary(jsreport.Binary.OSX.JsReportBinary.GetBinary());
                }
    


  • You seems to be using OSX binary on Linux host...


Log in to reply
 

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