简体   繁体   English

Google Apps Script:用于将文本文档转换为 PDF 的代码?

[英]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.我想要一段代码来转换 PDF 文件中的 google docs 文本文档模板。 I know how to create a new document as a google text document, but not how to transform it in a PDF file.我知道如何将新文档创建为谷歌文本文档,但不知道如何将其转换为 PDF 文件。 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?只有UrlFetchApp.fetch类?

One more question: can I automaticaly send this PDF file to be printed after I've created it?还有一个问题:我可以在创建后自动发送要打印的 PDF 文件吗?

Thanks!谢谢!

If I understand you correctly your question is about getting a text document as pdf ?如果我理解正确,您的问题是关于获取 pdf 格式的文本文档?

There is a dedicated method for that :有一个专门的方法:

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

see related documentation here 在此处查看相关文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM