javascriptpdfgoogle-apps-scriptgoogle-data-api

Google Apps Script: code to convert a text document in PDF?


I'd like a snipe of code to convert a google docs text document template in a PDF file. I know how to create a new document as a google text document, but not how to transform it in a PDF file. I find this piece of code:

var pdf = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&exportFormat=pdf&gid=1&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1", requestData).getBlob().setName(name);

  return pdf;

But I don't need spreadsheet customization (actually, I don't need spreadsheet, but text file).

How can I can do it? Only with UrlFetchApp.fetch class?

One more question: can I automaticaly send this PDF file to be printed after I've created it?

Thanks!


Solution

  • If I understand you correctly your question is about getting a text document as pdf ?

    There is a dedicated method for that :

    DocsList.getFileById('document ID').getAs('application/pdf');

    see related documentation here