Creating PDF From HTML Background Color In The PDF
I have seen several similar questions regarding creating PDF from Blob with examples of colored backgrounds, but none of the answers address the 'Background color issue' and I can'
Solution 1:
The answer was quite simple... found this surfing the net and added...
html { -webkit-print-color-adjust: exact; }
This is the code that now works...
function htmlToPDF() {
var html =
"<style> html { -webkit-print-color-adjust: exact; } </style>"
+ "<h1>Hello world</h1>"
+ "<p>This is just a paragraph"
+ "<p style='color:red;'>I am red</p>"
+ "<p style='color:blue;'>I am blue</p>"
+ "<p style='font-size:50px;'>I am big</p>"
+ "<table style='border-collapse: collapse; width: 698px; height: 115px; background-color: #C5D9F1;' border='0' cellpadding='10'>"
+ "<tbody>"
+ "<tr>"
+ "<td style='padding: 5px;background-color:powderblue;' nowrap='nowrap'><strong>Bold with background-color:</strong></td>"
+ "</tr>"
+ "</tbody>"
+ "</table>";
var blob = Utilities.newBlob(html, "text/html", "text.html");
var pdf = blob.getAs("application/pdf");
DriveApp.createFile(pdf).setName("text.pdf");
MailApp.sendEmail("[your email here ]", "PDF File", "", {htmlBody: html, attachments: pdf});
}
Post a Comment for "Creating PDF From HTML Background Color In The PDF"