I am currently running a cloud function to generate a .docx document and then deliver it to a user using nodemailer. Here is the code to generate the .docx file using docxtemplater:
const file_name = 'template.docx';// this is the file saved in my firebase storage
const templateRef = await admin.storage().bucket()
.file(file_name);
const template_content = (await templateRef.download())[0];
const zip = new PizZip(template_content);
let doc;
try {
doc = new Docxtemplater(zip, { linebreaks: true });
} catch (error) {
// Catch compilation errors (errors caused by the compilation of the template : misplaced tags)
errorHandler(error);
}
doc.setData({
name: data.name
});
try {
doc.render();
} catch (error) {
errorHandler(error);
}
const contentBuffer = doc.getZip().generate({ type: "nodebuffer" });
What I am trying to achieve now is to change that contentBuffer into a pdf file that can then be attached to an email. I tried using PDF make but it generated a blank pdf. Is there a way this can be done using any of the pdf Generators?
From a quick search I've found this info in the Docxtemplater's docs:
This also lists
PDFtron
andAspose
as another options if the results of the first one aren't good enough for your needs.