I have HTML files located in a Google Drive folder. I am trying to get the files, read content, convert to PDF and then save to the same folder.
The whole flow works fine, but most of the HTML formatting is lost (like fonts etc). Is there a way to convert HTML to PDF the same way as it looks in HTML?
Here the code:
function myFunction() {
var folder = DriveApp.getFolderById("0B9EI2E_9Cj9rT1JmVk5ESnhVbjA");
var contents = folder.getFilesByType(MimeType.HTML);
while (contents.hasNext()) {
var file = contents.next();
var fileName = file.getName();
var rawFileName = fileName.substring(0,fileName.indexOf("."));
var newFileName = rawFileName+".pdf";
var htmlBody = HtmlService.createHtmlOutput(file).getContent();
var blob = Utilities.newBlob(htmlBody, 'text/html').getAs('application/pdf').setName(newFileName);
folder.createFile(blob);
}
}