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"
+ "<pstyle='color:red;'>I am red</p>"
+ "<pstyle='color:blue;'>I am blue</p>"
+ "<pstyle='font-size:50px;'>I am big</p>"
+ "<tablestyle='border-collapse: collapse; width: 698px; height: 115px; background-color: #C5D9F1;'border='0'cellpadding='10'>"
+ "<tbody>"
+ "<tr>"
+ "<tdstyle='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"