1

I am generating the PDF from HTML. The run-time is node.js 10. The PDF is all-okay when the function is run in the firebase emulator. But the exact same code fails to produce a nicely formatted PDF. The part of CSS doesn't come into the effect.

How can I generate the well formatted PDF with google cloud functions running on Firebase/GCP ?

Below is the code snippet :

var htmlPdf = require('html-pdf');
........
........
async function generatePdf(htmlText,fileNumber) {

    var options = { 
        format: 'Letter',
        directory: "", 
        timeout: 540000,  // in milliseconds
        border: {
                    top: "1in",            // default is 0, units: mm, cm, in, px
                    //right: "0.2in",
                    bottom: "1in",
                    left: "1in"
                  }
    };
    const fileName = `/tmp/payment-receipt-${fileNumber}.pdf`;
    
    htmlPdf.create(htmlText,options).toFile(fileName ,async (err, res)=> {
        if (err) {
            console.log('Error EC-002 ',err);
            return 'NOK';
        }

        console.log('file created as : ',res.filename);
     });
....
....
}

I already tried removing CSS external link and adding the relevant CSS classes in the section of the HTML. It didn't work. There doesn't seem to be any problem with the external links since the HTML has one image (sourced from the internet) and it works well. There's absolutely no problem when the code is run on a firebase emulator.

Sukhi
  • 13,261
  • 7
  • 36
  • 53

0 Answers0