n8n pdf generator
Companies often have to generate the same pdf or document files numerous times in a work week. I wanted to see if there was a shortcut to automate this process in n8n.
My idea was to go from a central spreadsheet (Google Sheets or an Excel file), extract the info 1 row at a time, and generate a new file.
This video shows a final output in a folder, but in reality, you can attach these as emails, zip them up or much more. The workflow here should inspire you. A video is below if you would rather watch that then read the article.
If you are looking for help when it comes to building n8n workflows, I’m also taking on customers, so reach out.
The n8n Workflow
All it takes to build this workflow is the 6 nodes and 1 trigger below.
At the end we will go over other ways in which you can improve this workflow as well based on use cases.

Example Spreadsheet for the video
The spreadsheet used is quite basic. We have the city, franchise fee, franchise name, owner, and email. Often when it comes to generating docs, there are just a few fields that need to be changed.

You can use this in sheets, or if you want to follow along with the video, use a .xlsx file.
n8n Form Trigger
The workflow starts out by utilizing a form trigger to input the spreadsheet.

Extract From File
From there we extract the info from the spreadsheet as we will want it in json.

Loop over items
Each row in the spreadsheet needs to have a PDF/Doc associated with it. We will loop over these one at a time.
Copy File
Next we will want to copy the template we created for the PDF file. Below I have a super basic example for the video. Often in the real world, you’ll deal with docs that have formatting, different fonts, headers/footers and more. All can be used.
I put the variables in the brackets []. We will be using these to map information in the next node.

Now lets copy the template. We will want a Google Doc for each franchise. Select the copy Operation and the file. I also want a unique name for each file. In this case I just put franchise_letter_ and then the json for the franchise name.
I then selected the folder I want them to live in,

Update the Doc
Now that we duplicated our doc for the specific franchise, let’s fill in the bracket information. First drop in {{ $json.id }} to match the document from the previous node.
Use Find and Replace Text to fill in the different variables. For the example of [Owner] we use the the json from the spreadsheet earlier.

Repeat this for the rest of the text fields.
Update Integer
For an integer, it’s a bit more complicated. You have to wrap String() around the data, otherwise you will have an error.

Update Time
Lastly, often docs are dated for the same day. We can use {{ $now.toFormat(“MM/dd/yyyy”) }} to get the exact date. Feel free to change the format of the date as needed.

Download The Doc & Convert it to PDF
Lastly, we will want to download the doc we created as a PDF and then upload it back into the Google Drive folder.

To download the file, use the documentId again. In the Google File Conversion select PDF under Docs.

Now let’s reupload it. Choose a unique file name, and the folder once again.

Additional Improvements to the Workflow
From this basic template, there are so many ways to expand this out. You could automatically attach the PDF as an email attachment and draft a message to send.
If the same owner needed multiple PDF files, you can add these all to a ZIP file.
A slack notification can be built to tag support that files are ready.
Final Thoughts
Thanks for checking out this n8n article. If you need any help with automations hit us up. In the meantime, check out our other n8n articles and videos.
Ryan is a Data Scientist at a fintech company, where he focuses on fraud prevention in underwriting and risk. Before that, he worked as a Data Analyst at a tax software company. He holds a degree in Electrical Engineering from UCF.