I tried to send a customed HTML ( CSS) as PDF but the pdf sent turns out black and white. I hope someone helps me out, thanks :)
here is my function :
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)],
});
});
}
CodePudding user response:
try this website
Convert web pages or HTML files to PDF documents
CodePudding user response:
On a Windows computer, open an HTML web page in Internet Explorer, Google Chrome, or Firefox. ... Click the “Convert to PDF” button in the Adobe PDF toolbar to start the PDF conversion. Enter a file name and save your new PDF file in the desired location.