title: Generation of PDF from Google Form using Doc template using Script
body: <p>I am using this script to create PDF from Google from using template in Google Docs.</p>
  <p>The script I am using is as below:</p>
  <pre><code>function afterFormSubmit(e) {
      const info = e.namedValues;
      const pdfFile = createPDF(info);
      const entryRow = e.range.getRow();
      const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Sheet2&quot;)
      ws.getRange(entryRow, 63).setValue(pdfFile.getUrl());
      ws.getRange(entryRow, 64).setValue(pdfFile.getName());
      
      sendEmail(e.namedValues ['Email address'][0],pdfFile);
  }
  
  
  function sendEmail(email,pdfFile){
    
    GmailApp.sendEmail(email, &quot;Daily Transation Summary Report&quot;, &quot;Please find the attached DTR&quot;, {
      attachments : [pdfFile],
      name: 'My Company'
  });
  
  }  
    
  function createPDF(info) {
    
    const pdfFolder = DriveApp.getFolderById(&quot;1ebglel6vwMGXByeG4wHBBvJu9u0zJeMJ&quot;);
    const tempFolder = DriveApp.getFolderById(&quot;1ebglel6vwMGXByeG4wHBBvJu9u0zJeMJ&quot;);
    const templateDoc = DriveApp.getFileById(&quot;1kyFimRMdHQZV85F5P6JyCHv1DQ3KJFv1hx5o7lIcNZo&quot;);
    
    const newTempFile = templateDoc.makeCopy(tempFolder);
    const openDoc = DocumentApp.openById(newTempFile.getId());
    const body = openDoc.getBody();
    body.replaceText(&quot;{Name of Person}&quot;, info['Name of Person'][0]);
    body.replaceText(&quot;{Date of Report}&quot;, info['Date of Report'][0]);
    body.replaceText(&quot;{Name of Outlet}&quot;, info['Name of Outlet'][0]);
    body.replaceText(&quot;{Opening Petty Cash Balance}&quot;, info['Opening Petty Cash Balance'][0]);
    body.replaceText(&quot;{Total Petty Cash Received}&quot;, info['Total Petty Cash Received'][0]);
    body.replaceText(&quot;{Closing Petty Cash Balance}&quot;, info['Closing Petty Cash Balance'][0]);
    body.replaceText(&quot;{Total Petty Cash Paid}&quot;, info['Total Petty Cash Paid'][0]);
    body.replaceText(&quot;{Available Float Cash Balance}&quot;, info['Available Float Cash Balance'][0]);
    body.replaceText(&quot;{Milk For Outlet}&quot;, info['Milk For Outlet'][0]);
    body.replaceText(&quot;{Staff Milk/Toast etc.}&quot;, info['Staff Milk/Toast etc.'][0]);
    body.replaceText(&quot;{Petrol Expenses}&quot;, info['Petrol Expenses'][0]);
    body.replaceText(&quot;{Water Tank Charges}&quot;, info['Water Tank Charges'][0]);
    body.replaceText(&quot;{Repair And Maintenance}&quot;, info['Repair And Maintenance'][0]);
    body.replaceText(&quot;{Freight Paid}&quot;, info['Freight Paid'][0]);
    body.replaceText(&quot;{Purchase of Soya Chaap}&quot;, info['Purchase of Soya Chaap'][0]);
    body.replaceText(&quot;{Purchase of Rumali Roti}&quot;, info['Purchase of Rumali Roti'][0]);
    body.replaceText(&quot;{Purchase of Egg Tray}&quot;, info['Purchase of Egg Tray'][0]);
    body.replaceText(&quot;{Other Expenses}&quot;, info['Other Expenses'][0]);
    body.replaceText(&quot;{Total Tip Amount (PAYTM &amp; CARD)}&quot;, info['Total Tip Amount (PAYTM &amp; CARD)'][0]);
    body.replaceText(&quot;{Cash Sales - Outlet}&quot;, info['Cash Sales - Outlet'][0]);
    body.replaceText(&quot;{Cash Sales - KCCO App}&quot;, info['Cash Sales - KCCO App'][0]);
    body.replaceText(&quot;{Card Sales}&quot;, info['Card Sales'][0]);
    body.replaceText(&quot;{Credit (Udhar) Sales}&quot;, info['Credit (Udhar) Sales'][0]);
    body.replaceText(&quot;{Paytm Sales}&quot;, info['Paytm Sales'][0]);
    body.replaceText(&quot;{KCCO App Sales Razor Pay}&quot;, info['KCCO App Sales Razor Pay'][0]);
    body.replaceText(&quot;{Swiggy Sales}&quot;, info['Swiggy Sales'][0]);
    body.replaceText(&quot;{Zomato Sales}&quot;, info['Zomato Sales'][0]);
    body.replaceText(&quot;{Dunzo Sales}&quot;, info['Dunzo Sales'][0]);
    body.replaceText(&quot;{Zomato Gold Sales}&quot;, info['Zomato Gold Sales'][0]);
    body.replaceText(&quot;{Dine Out Sales}&quot;, info['Dine Out Sales'][0]);
    body.replaceText(&quot;{Total Cancelled Bill Amount}&quot;, info['Total Cancelled Bill Amount'][0]);
    body.replaceText(&quot;{Total Sales of the Day (Total of Above)}&quot;, info['Total Sales of the Day (Total of Above)'][0]);
    body.replaceText(&quot;{Total Sales of the Day (As Per PetPooja)}&quot;, info['Total Sales of the Day (As Per PetPooja)'][0]);
    body.replaceText(&quot;{Old Due Receipts  - Cash}&quot;, info['Old Due Receipts  - Cash'][0]);
    body.replaceText(&quot;{Old Due Receipts - Other Modes}&quot;, info['Old Due Receipts - Other Modes'][0]);
    body.replaceText(&quot;{Tip Receipts - Card}&quot;, info['Tip Receipts - Card'][0]);
    body.replaceText(&quot;{Tip Receipts - Paytm}&quot;, info['Tip Receipts - Paytm'][0]);
    body.replaceText(&quot;{Currency Note of INR 2000}&quot;, info['Currency Note of INR 2000'][0]);
    body.replaceText(&quot;{Currency Note of INR 500}&quot;, info['Currency Note of INR 500'][0]);
    body.replaceText(&quot;{ Currency Note of INR 200}&quot;, info[' Currency Note of INR 200'][0]);
    body.replaceText(&quot;{Currency Note of INR 100}&quot;, info['Currency Note of INR 100'][0]);
    body.replaceText(&quot;{Currency Note of INR 50}&quot;, info['Currency Note of INR 50'][0]);
    body.replaceText(&quot;{Currency Note of INR 20}&quot;, info['Currency Note of INR 20'][0]);
    body.replaceText(&quot;{Currency Note of INR 10}&quot;, info['Currency Note of INR 10'][0]);
    body.replaceText(&quot;{Other Currency Note/Coins}&quot;, info['Other Currency Note/Coins'][0]);
    body.replaceText(&quot;{Total Available Cash to Handover}&quot;, info['Total Available Cash to Handover'][0]);
    body.replaceText(&quot;{S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit&quot;, info['S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit'][0]);
    body.replaceText(&quot;{Total No. of Bills of Credit Recovery}&quot;, info['Total No. of Bills of Credit Recovery'][0]);
    body.replaceText(&quot;{S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received}&quot;, info['S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received'][0]);
    body.replaceText(&quot;{Total No. of Complementary Bills  During the Day}&quot;, info['Total No. of Complementary Bills  During the Day'][0]);
    body.replaceText(&quot;{S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled}&quot;, info['S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled'][0]);
    body.replaceText(&quot;{Total No. of Cancelled Bills During the Day}&quot;, info['Total No. of Cancelled Bills During the Day'][0]);
    body.replaceText(&quot;{S.No.//Name of Person// Mobile No// Bill No// Bill Amount}&quot;, info['S.No.//Name of Person// Mobile No// Bill No// Bill Amount'][0]);
    body.replaceText(&quot;{S.No.// Bill No// Mode of Payment//Tip Amount Received}&quot;, info['S.No.// Bill No// Mode of Payment//Tip Amount Received'][0]);
    body.replaceText(&quot;{No. of Cylinders Received at Outlet}&quot;, info['No. of Cylinders Received at Outlet'][0]); 
    
    openDoc.saveAndClose();
    
    const blobPDF = newTempFile.getAs(MimeType.PDF);
    const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Name of Outlet'][0]+ &quot; &quot; + info['Date of Report'][0]);
    tempFolder.removeFile(newTempFile);
      
    return pdfFile;
    
  }                                         
  </code></pre>
  <p>This script is not generating PDF as well PDF is not being Mailed.</p>
  <p>The link of Spreadsheet is as below</p>
  <p><a href="https://docs.google.com/spreadsheets/d/1m6Aca0TcLf5UZ7P9CvAdQDokoazQljsqDT6CGh0K3j4/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1m6Aca0TcLf5UZ7P9CvAdQDokoazQljsqDT6CGh0K3j4/edit?usp=sharing</a></p>
  <p>Please guide.</p>