I am quite new to firebase cloud functions and I am trying to get a PDF document generated and saved (either locally, in the firebase storage or even in the browser to then be sent to the user via nodemailer).
Below is the code I have so far but nothing gets created/ generated. I just get a 'crash' response on the Firebase log when the function is run:
const functions = require("firebase-functions");
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
const cors = require('cors')({origin: true});
var pdf = require('pdfmake');
var printer = new pdf();
var fs = require('fs');
var BUCKET = 'gs://mpca-19527.appspot.com'
admin.initializeApp();
exports.createWill = functions.https.onRequest((req, res) => {
var docDefinition = {
pageSize: 'A4',
pageMargins: [ 40, 60, 40, 60 ],
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
var pdfDoc = printer.createPdfKitDocument(docDefinition);
let file_name = 'facture.pdf';
const myPdfFile = storage.bucket(BUCKET).file(file_name);
pdfDoc.pipe(fs.createWriteStream('document.pdf'));
pdfDoc.end()
});
This is just a test snippet to even see how the PDFmake works and I cannot seem to get it to work. Can a pdf be generated and stored locally off a http request?