This is a little script to create a PDF file using a Google Doc template and the values in a Google Spreadsheet.
The script takes the fields from the active row in the active sheet the script is contained in and using a Google Doc template (identified by TEMPLATE_ID) creates a PDF doc with these fields replacing the place-holders in the template. The place-holders are identified by having a % either side, e.g. %Name%. It is invoked by the “Create PDF” menu.
So to use:
- Create a Google Doc as a template using the placeholders with %’s around the words, e.g. %Name%. Make a note of the ID number (https://docs.google.com/document/d/ID NUMBER HERE/edit)
- Create a new Google Spreadsheet and give it header names (first row) that match up with the placeholders minus the %’s, e.g. Name or Age (it is case-sensitive).
- 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
- Put the actual values you want to use in the spreadsheet under the appropriate columns, one row for each PDF file.
- Click a cell on a row of values you would like to use to select that row and click Create PDF > Create PDF.
The new PDF will be created after a few moments in the root of your Google Drive with the name ‘Copy of <template name>’.pdf.