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

强颜欢笑 提交于 2021-02-08 11:00:35

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/20256517/google-apps-script-code-to-convert-a-text-document-in-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!