2017-04-02 33 views
0

我目前正在使用Form Publisher添加PDF来从表单响应中使用我需要的模板,但它允许我在一个月内只生成100个文件。我有月最少500个文件的要求,我无法承担Form Publisher的高级授权购买。请帮助我使用基本脚本来基于表单响应数据和我所需的模板生成PDF。使用模板从表单响应中生成PDF。

我会分享模板和样本表,如果可以完成的话。

问候 Gopikrishna

回答

0

什么工具可以为您的使用情况?如果使用pdftk,则有一个fill_form命令可以将FDF/XFDF数据作为PDF &,并将它们结合起来。

+0

谢谢你回复Robbat!事实上,我没有这样的工具,真的不知道这个工具如何将谷歌形式的反应与保存为PDF的单词模板联系起来。我真的在寻找一个脚本,我们可以使用google appscript自动执行,而不是使用第三方工具。 –

-1

此片段使用Google文档模板和Google Spreadsheet中的值创建PDF文件。只要将它放到您正在使用的GSheet的脚本编辑器中即可。

// Replace this with ID of your template document. 
var TEMPLATE_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' 

// var TEMPLATE_ID = '1wtGEp27HNEVwImeh2as7bRNw-tO4HkwPGcAsTrSNTPc' // Demo template 

// You can specify a name for the new PDF file here, or leave empty to use the 
// name of the template. 
var PDF_FILE_NAME = '' 

/** 
* Eventhandler for spreadsheet opening - add a menu. 
*/ 

function onOpen() { 

    SpreadsheetApp 
    .getUi() 
    .createMenu('Create PDF') 
    .addItem('Create PDF', 'createPdf') 
    .addToUi() 

} // onOpen() 

/** 
* Take the fields from the active row in the active sheet 
* and, using a Google Doc template, create a PDF doc with these 
* fields replacing the keys in the template. The keys are identified 
* by having a % either side, e.g. %Name%. 
* 
* @return {Object} the completed PDF file 
*/ 

function createPdf() { 

    if (TEMPLATE_ID === '') { 

    SpreadsheetApp.getUi().alert('TEMPLATE_ID needs to be defined in code.gs') 
    return 
    } 

    // Set up the docs and the spreadsheet access 

    var copyFile = DriveApp.getFileById(TEMPLATE_ID).makeCopy(), 
     copyId = copyFile.getId(), 
     copyDoc = DocumentApp.openById(copyId), 
     copyBody = copyDoc.getActiveSection(), 
     activeSheet = SpreadsheetApp.getActiveSheet(), 
     numberOfColumns = activeSheet.getLastColumn(), 
     activeRowIndex = activeSheet.getActiveRange().getRowIndex(), 
     activeRow = activeSheet.getRange(activeRowIndex, 1, 1, numberOfColumns).getValues(), 
     headerRow = activeSheet.getRange(1, 1, 1, numberOfColumns).getValues(), 
     columnIndex = 0 

    // Replace the keys with the spreadsheet values 

    for (;columnIndex < headerRow[0].length; columnIndex++) { 

    copyBody.replaceText('%' + headerRow[0][columnIndex] + '%', 
         activeRow[0][columnIndex])       
    } 

    // Create the PDF file, rename it if required and delete the doc copy 

    copyDoc.saveAndClose() 

    var newFile = DriveApp.createFile(copyFile.getAs('application/pdf')) 

    if (PDF_FILE_NAME !== '') { 

    newFile.setName(PDF_FILE_NAME) 
    } 

    copyFile.setTrashed(true) 

    SpreadsheetApp.getUi().alert('New PDF file created in the root of your Google Drive') 

} // createPdf() 
相关问题