I attempted to send a customized HTML (+CSS) as a PDF, but the resulting PDF sent is only in black and white. I would appreciate any assistance with this issue. Thank you :)
Below is the function that I used:
function sendEmails() {
var data = getBody("DATA");
var emailData = rowsToObjects(data);
emailData.forEach(function (rowObject) {
//var emailSubj = 'Konfirmasi Tagihan TUNEECA tanggal '+rowObject['TANGGAL AWAL']+' - '+rowObject['TANGGAL AKHIR']
const pdfhtml = HtmlService.createHtmlOutputFromFile('body-pdf').getContent();
const data = renderHtml(rowObject);
const htmlContent = pdfhtml.replace('hereismytabledata',data).replace('$CUSTNAME',rowObject['NAMA PARTNER']);
const blob = Utilities.newBlob(htmlContent, MimeType.HTML);
blob.setName('Rincian Tagihan.pdf');
var emailSubjectTemplate = 'Konfirmasi Tagihan tanggal {{TANGGAL AWAL}} - {{TANGGAL AKHIR}} ';
var emailBodyTemplate = HtmlService.createHtmlOutputFromFile('body-email').getContent();
var emailSubject = renderTemplate(emailSubjectTemplate, rowObject);
var body = renderTemplate(emailBodyTemplate, rowObject);
const recipientEmail = rowObject['EMAIL'];
console.log(emailSubject,body,recipientEmail)
MailApp.sendEmail({
to: recipientEmail,
subject: emailSubject,
htmlBody: body,
attachments: [blob.getAs(MimeType.PDF)],
});
});
}
Here is my HTML : https://i.sstatic.net/bPGry.png
and here is the result PDF sent by email: https://i.sstatic.net/Ldw9I.png
Note: I apologize for submitting HTML as a picture due to an error while trying to edit and add some codes.