Generate Dynamic Invoices using Integromat and PDF4me

By Nishanth Asokan | Automation

Generate Dynamic Invoices using Integromat and PDF4me

Dynamic document generation is the process of automatically creating a batch of documents that are personalized with dynamic data from a source. For example, an Invoice might be personalized to address each recipient by name. Creating documents with dynamic data would require a data source, like a list, spreadsheet, database, JSON, or arrays. Merge fields are placeholders in predefined templates that are later replaced using data from one of the above-mentioned or any other supported data sources.

Creating an invoice with dynamic data requires the application of techniques like mail merge or using merge fields. One of the most popular methods of dynamic document generation involves the use of mustache rendering, which is far easier in designing templates. Custom invoices are based on document templates created using Word or other form creators that have to merge field capabilities. Here we discuss the use of templates created using the mustache syntax - {{placeholder field}} - which is later replaced with the dynamic data.

PDF4me Generate Document action in Integromat lets you create scenarios to generate dynamic documents and automate them. The generation process can be automated if you have the template and the dynamic data ready. The template can be a Word file or HTML, or any other supported format. The data can be a Spreadsheet, CSV, JSON, XML, or data list.

Generating a Dynamic Invoice

Generating an Invoice with Dynamic Data using Integromat requires the template and data to be stored in a cloud storage platform. At least, the template should be in cloud storage like Dropbox, but the data can be passed to an input data field directly.

Let’s look to create a sample invoice like below using an Integromat scenario.

Mustache template for dynamic invoicing

In our use case, the following sample is expected to be available at a Dropbox location.

Add a watch for files trigger to start the scenario

Create a Dropbox module to watch for the templates arriving. As soon as the new template file arrives in the folder, the scenario is triggered.

Watch files action for Dropbox module

Add a Download file Dropbox action

Once the template file is detected in the source folder, the Dropbox module with the Download file action will pass the file from the storage to the PDF4me action. We need to add 2 Download files action.

One for downloading the Template.

Download file action for Dropbox module

Another for Downloading the JSON data

Download JSON data from Dropbox

Add PDF4me module for Generate Document Action

Next in the scenario, we have to add the PDF4me module with the Generate Document Action. Here, you need to configure the Template type, the Output type, and the Input data. The input data can either be directly entered into the field or in our case, configure to get the data from the JSON file.

PDF4me Generate Document module for Integromat

The data for the input field should look like below for the template in the use case:

{
    "Documents": [
        {
            "header": {
                "docType": "Original Copy"
            },
            "body": {
                "Column1": "Quantity",
                "Column2": "Description",
                "Column3": "Unit Price",
                "Column4": "Total",
                "Invoice": {
                    "number": 14957,
                    "date": "25-02-2022",
                    "instructions": "Instruction Invoice 1",
                    "subTotal": 200150,
                    "tax": "18%",
                    "dueDate": "25-03-2022",
                    "shipping": "200"
                },
                "Biller": {
                    "phone": "989797",
                    "fax": "998463",
                    "email": "[email protected]",
                    "web": "www.doc1.com",
                    "address": {
                        "company": "Organization 1",
                        "street": "Street 1",
                        "city": "City 1",
                        "zip": "123456"
                    }
                },
                "Recepient": {
                    "name": "recepeint 1",
                    "address": {
                        "street": "testveien 3 ",
                        "city": "City 1",
                        "zipcode": "0555",
                        "country": "Country 1"
                    }
                },
                "Product": [
                    {
                        "quantity": 1,
                        "description": "item 1",
                        "unitPrice": 45,
                        "totalPrice": 867
                    },
                    {
                        "quantity": 2,
                        "description": "item 2",
                        "unitPrice": 123,
                        "totalPrice": 3464
                    },
                    {
                        "quantity": 3,
                        "description": "item 3",
                        "unitPrice": 323,
                        "totalPrice": 6564
                    }
                ]
            },
            "footer": {
                "phone": "phone123",
                "fax": "fax123",
                "email": "[email protected]",
                "web": "www.123.com"
            }
        
        }
    ]
}

Add an Iterator to handle the multiple output files

As it is obvious, the PDF4me action will generate multiple files based on the data. To handle this we need an Integromat Iterator module to handle each file for the next action.

Flow control iterator for output files

Add Dropbox Upload module to save the output files

Create a Dropbox module with the Upload files action to save all the files to the desired folder.

Upload files action for Dropbox module

The output of our scenario should look similar to the below document.

Final merged template

With a PDF4me Developer Subscription, you can create scenarios in Integromat that can automate the mass generation of documents with dynamic data at low cost. The subscription ensures your automation never stops due to any shortage in the number of API calls.

Related Blog Posts