2017-04-02 23 views
0

私は現在、必要なテンプレートを使用してフォーム応答からPDFを作成するためにForm Publisherアドインを使用していますが、月に100個のファイルしか生成できません。私は月に最低500ファイルの要件があり、Form Publisherのプレミアムライセンスを購入する余裕はありません。私の望むテンプレートでフォーム応答データに基づいてPDFを生成するための基本的なスクリプトを手伝ってください。テンプレートを使用してフォーム応答からPDFを生成する。

テンプレートとサンプルシートを共有することができます。あなたの使い方にはどんなツールがあります

よろしく Gopikrishna

答えて

0

pdftkを使用する場合は、コマンドを使用して、PDF & FDF/XFDFデータを取得し、2つを組み合わせることができます。

+0

ロバートに応答していただきありがとうございます。実際に私はそのようなツールを持っていないし、実際にこのツールがどのようにPDFとして保存される単語テンプレートにGoogleフォームの応答をリンクしていない。私は実際にサードパーティのツールを使用するのではなく、Googleのappscriptで自動化できるスクリプトを探しています。 –

-1

このスニペットは、GoogleドキュメントテンプレートとGoogleスプレッドシートの値を使用してPDFファイルを作成します。あなたが使用しているGSシートのスクリプトエディタの直前にあります。

// 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() 
関連する問題