通过Google Apps脚本将Google文档的特定页面导出为PDF

时间:2018-04-06 12:19:11

标签: google-apps-script google-docs export-to-pdf

原始代码基本上将Google Doc转换为基于2种不同模板的PDF(2种不同的Google Doc和2种不同的密钥);

从Google表单回复中,如果选择了标准部分,它将向用户发送附有报价单的电子邮件(PDF格式)。如果没有,则会向用户发送不同的模板:

第一个模板 - >报价(标准件)
第二个模板 - >已收到请求模板(非标准部分)

所以我现在尝试做的不是使用2个不同的文档,我希望将模板放在1个文档中,而只转换特定的页面。例如,第1页中的模板1和第2 - 4页中的模板2。

下面的代码只会将整个文档转换为PDF,所以我想知道是否有特殊的方法或属性如getpagenumber来转换特定的页面。

var docName = "insertdocnamehere";
var custName = "insertcustomernamehere";
var docTemplate = "insertgoogledockeyhere";

var copyId = DriveApp.getFileById(docTemplate)
  .makeCopy(docName+' for '+ custName)
  .getId();

// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);

// Get the document’s body section
var copyBody = copyDoc.getActiveSection();

copyDoc.saveAndClose();
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

0 个答案:

没有答案
相关问题