Rendering issue with v3 and v4 , working fine with v2



  • Hi Team,

    We are facing rendering issue for PDF and Excel files using handlebar files

    Using module
    @jsreport/jsreport-core / @jsreport/jsreport-handlebars/@jsreport/jsreport-phantom-pdf/@jsreport/jsreport-xlsx/@jsreport/jsreport-assets

    For PDF rendor : getting worker crashed
    For xlsx rendor : getting render issue


  • administrators

    hi! please share the template that it is giving you these errors



  • Hi @bjrmatos ,

    Sorry for the delay in reply.

    Below is the code snippet that I have written (this is working fine in local but in dev stack it is throwing this error).

    public async genratePDFMailBody(templateId, templateData, logger: LogHelper, complexReport?) {
            let content = null;
            //S3 implementation replace below code
            var s3utils = new S3Utils();
            content = await s3utils.getRequestBody(templateId);
            logger.info('Content from S3 ', content);
            content = content.toString('utf8');
    
            // Initialize jsreport with phantom configuration
            var jsreport = require('@jsreport/jsreport-core')();
            jsreport.use(require('@jsreport/jsreport-phantom-pdf')());
            jsreport.use(require('@jsreport/jsreport-handlebars')());
            jsreport.use(require('@jsreport/jsreport-assets')({
                searchOnDiskIfNotFoundInStore: true,
                allowedFiles: "**/*.*",
            }));
    
            let data = await jsreport.init().then(function () {
                logger.info("Template Data: %s", JSON.stringify(templateData));
                return jsreport.render({
                    template: {
                        content: content,
                        engine: 'handlebars',
                        recipe: 'phantom-pdf',
                        helpers: `
                         function now() {return new Date().toLocaleDateString()}
                         function nowPlus20Days() {var date = new Date();date.setDate(date.getDate() + 20);return date.toLocaleDateString()}
                         function commaSeperation(num){if(num===null || num===0) {return 0;} else {return parseFloat(num).toLocaleString('en-us', {minimumFractionDigits: 2});}}
                         function due(total, tax){return commaSeperation((parseFloat(total)+parseFloat(tax)).toFixed(2))}
                         function totalSubGroup(items) {var sum = 0;items.forEach(function(i) {sum +=parseFloat(i.amountPrinted);});return parseFloat(sum).toFixed(2);}
                         function groupPercent(subGrpTotal,printTotal){var a = Math.round(parseInt((parseFloat(subGrpTotal)/parseFloat(printTotal))* parseInt(100)).toFixed(2));return parseFloat(a);}
                         function subGrpTax(subGrpTotal, taxRate){return commaSeperation((parseFloat(subGrpTotal)* parseFloat(taxRate)).toFixed(2))}
                         function distinctValCount(data) {var uniqueNames = []; var uniqueObj = [];for(i = 0; i< data.length; i++){ if(uniqueNames.indexOf(data[i].printerSticker) === -1){uniqueObj.push(data[i]);uniqueNames.push(data[i].printerSticker); }} return parseInt(uniqueObj.length);}
                         function toCamelCase(str){ return str.split(' ').join('_')}
                         function monoTotal(items,monopercent){var sum = 0;var a=0;items.forEach(function(i){  if(i.name =='Monochrome Printing'){ sum +=parseFloat(i.price);}}); a = sum *monopercent; return parseFloat(a).toFixed(2); }
                         function colorTotal(items,colorpercent){var sum = 0;var a=0; items.forEach(function(i) {if(i.name =='Color Printing'){sum +=parseFloat(i.price);}});var a = sum *colorpercent;return parseFloat(a).toFixed(2);}
                         function printedTotal(monototal,colortotal){var sum = 0;sum= parseFloat(monototal)+parseFloat(colortotal);return parseFloat(sum).toFixed(2);}
                         function totalWtTax(tax, printTotal){ var sum=0;sum+=parseFloat(printTotal)+parseFloat(tax);return parseFloat(sum).toFixed(2);}
                         function total(items){var sum = 0; items.forEach(function (i) {console.log('Calculating item ' + i.name + '; you should see this message in debug run'); sum += i.price;}) return sum;}
                         `
                    },
                    data: templateData
                }).then(function (resp) {
                    return resp.content;
                });
            }).catch(function (e) {
                logger.error("Rendring error: ", ErrorType.RenderingError, e, JSON.stringify(e));
                return null;
            });
            return data;
        }
    

    Template is Invoice template which we have online jsreport playground(without style sheet and Asset files).

    [0_1739892019743_Invoice](Uploading 100%)

    Error I am getting
    {   "code": "WORKER_CRASHED" }

    Please look into this issue and help.

    Thanks



  • Thanks for the code, but we are still missing many pieces that we need to help you...
    Can you run the code with env variable DEBUG=jsreport and share the stdout output?

    Btw, do you need to use phantomjs which has been deprecated for a long time? The chrome-pdf should be the replacement.



  • Thanks for the reply @admin
    So it means it is no longer supported ? If that is the case what are the steps which we need to follow if we want to switch from phantom to chrome pdf recipe. Potentially what changes do we have to make in the above given logic(except requiring a chrome pdf package and changing recipe).

    Note : we are running above logic in AWS lambda and it is a serverless application.

    Thanks in advance.



  • The phantom-pdf recipe is still supported from us. However, the underlying technology phantomjs is archived for 2 years. Thus the recipe is deprecated and its recommended to switch to chrome-pdf.

    The migration flow depends. You need to test yourself, because the sizes can vary and you may need to adapt your styles or use zoom css.

    The chrome needs extra binary for aws lambda. You better follow our official tutorial
    https://jsreport.net/learn/aws-lambda-serverless



  • Hi @admin ,

    Thank you for the clarification.
    Yes we will plan to switch to chrome-pdf, but we need some time as multiple external teams will get impacted due to this upgrade.
    We need to make it work until that migration takes place. As you asked I have added jsreport environment variable and now I am seeing below logs. Please check and help

    Recipe: phantom-pdf

    **Error#1

    Report render failed
    (Because) Worker unexpectedly exited
    Error: Worker unexpectedly exited**

    Sorry I am unable to attach the screenshot

    Note : I am explicitly installing @jsreport/jsreport-phantom-pdf (v4.1.0) since it is not included in jsreport (v 4.7.0) and node version is 18.

    Thanks in advance.



  • These aren't stdout logs but an error message...

    Try to isolate the problem, are you able to render an html template? The problem can be that the phantomjs binary isn't working in the aws lambda environment.



  • I am able to render html template, xlsx template.
    While rendering pdf I am getting this Worker crashed problem.
    After setting debug environment variable only I am able to see the above log messages in the cloud watch before that I was not able to see these logs also.

    Is there any working solution for this issue?



  • So its the problem with phantomjs... You may need to download and use the phantomjs binary compiled for amazon linux.

    I see the mention this one here
    https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
    You would replace the binary in the zip package you upload to aws.


Log in to reply
 

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