PDF Creator – Send multiple PDFs based on selected rows

GSheet example

This script creates a number of PDF files using a Google Doc template and the rows selected in a Google Spreadsheet.

Further to user requests, I have created many variations on the PDF creation theme.

Get in touch now if you need any help with this or any other GAS scripts or have a look through some other free scripts and snippets.

There is a Gist and a demo spreadsheet you can take a copy of to use and see the script.

The script takes the fields from each of the selected rows in the GSheet “containing” the script and, using a Google Doc template (identified by TEMPLATE_ID), creates multiple PDFs. The fields replace the place-holders in the template. The place-holders are identified by having a << or >> either side, e.g. <<Name>>.

It is invoked by the “Create PDFs” menu.

You can also:

  • specify a name for the PDF file in a column called “File Name”
  • automatically email the PDF by specifying a recipient in a “Email” column
  • specify the folder that the PDFs are stored in using RESULTS_FOLDER_ID
  • use placeholders in the template header

If it finds a “Date Sent” column the script also records the date/time the PDF was sent.

Installation

  1. Create a Google Doc as a template using the place-holders with << and >> around the words, e.g. <<Name>>. Make a note of the ID number (https://docs.google.com/document/d/ID NUMBER HERE/edit). Like this for example.

GDoc template example

  1. Create a new Google Spreadsheet and give it header names (first row) that match up with the placeholders minus the angle brackets, e.g. “Name” or “Age” (it is case-sensitive), and optionally one called “File Name” to specify the name of the PDF file created and “Email” to specify who the PDF should be emailed to.

GSheet example

 

  1. Copy the script into Code.gs in the script editor (Tools > Script editor), paste the template ID number into TEMPLATE_ID value (between the ”s) and add a file name for the new PDF in PDF_FILE_NAME if you don’t want to use the template name.
  2. Complete EMAIL_SUBJECT and EMAIL_BODY if you are sending the PDF as an email attachment
  3. Update the GSheet. Put the actual values you want to use in the spreadsheet under the appropriate columns, one row for each PDF file. This could be the responses from a Google Form.
  4. Select the rows that you want to create and send PDFs from.
  5. Click the custom menu “Create PDFs > Create PDFs for selected rows” in the GSheet.