Reputation: 586
I have a document that i use as a template, url: https://docs.google.com/document/d/1Ng00Sw0V-3_htLF2-SyPj895g_V9bi1mKQc1LOaHPNY/edit?usp=sharing
I'm using a script when a form is submited and export it to pdf
function testExport() {
var pdf = DocumentApp.openById(docTemplate).getAs("application/pdf");
DriveApp.createFile(pdf);
};
But the exported link looks like https://drive.google.com/file/d/0B_YrT5Ue-LAvUllyQ0ZpbkRodVU/view?usp=sharing
Size of rows between the table seems to increased and the overall quality looks bad, is there a way to fix it? When I download the doc file as pdf the then it looks really good.
Upvotes: 0
Views: 321
Reputation: 12673
Document.getAs()
uses a slightly different converter then the Google Docs UI does. You can get closer by using the conversion functionality built into the Drive API, exposed in File.exportLinks
. The sample below uses the Drive Advanced Service to do the conversion and save the result.
function exportAsPdf(documentId) {
var file = Drive.Files.get(documentId);
var url = file.exportLinks['application/pdf'];
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + token
}
});
var contents = response.getBlob();
contents.setName(file.title + '.pdf');
DriveApp.createFile(contents);
}
Upvotes: 1