On this page
Unleash your genius.
Get genius ideas, actionable tips, and smart solutions in your inbox once a month.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Automatically Populate PDF and Word Documents from a MySQL Database

June 20, 2016
Min Read

Building internal database systems can be a great way to organize your organizations data. With a tool like MySQL, you can build flexible databases that integrate across your entire organization and can scale as your business grows.

With Formstack Documents you can easily integrate your MySQL databases to automatically generate all types of documents - such as contracts, invoices, reports, and more. In this example, we’re going to show you how to automatically generate an invoice when we add a new order to our database and email it to our customer.

To get started, we’re going to setup the template for our invoice in Formstack Documents. From the Documents page in Formstack Documents, click the New Document button and enter a name. On the next step, pick Build Your Own document type and continue.

On the next step, you’ll be taken to the Document Builder. Here’s where you are going to build your template. You can add your logo, contact information, and other boilerplate invoice info. Then for the spots that you want to insert the invoice data, you’re going to use merge fields that look like {$Name}, {$Address}, {$Description}, etc.

Here's what our invoice template looks like:

Once you have your template finished, go ahead and save and then move on to the Settings tab. Here, you can modify various options like the type of file that is generated and the name of the file. For this example, we’re going to generate a PDF and we’re going to include the order number in the file name.

Next, we’re going to setup the email delivery so that our invoice is automatically emailed to our customer. From the Deliver tab, go ahead and Edit the default email delivery. For the To address, we’re going to use a merge field (ie something like {$Email}). Feel free to change any of the other email settings.

After we’re finished up our email delivery, we are done with the setup process in Formstack Documents and we’re ready to setup the integration with our MySQL database. To help with the integration, we’re going to use our friends over at Zapier.

Inside Zapier, go ahead and create a New Zap. For the Trigger, we’re going to choose MySQL as the service and then New Row as the trigger.

After you authenticate your MySQL database, you’ll need to choose which table you want to monitor. Go ahead and pick your order table.

Next, we’re going to setup the Action of our Zap. For the service, we’re going to choose Formstack Documents and then Create Document Merge as the action.

After you authenticate your Formstack Documents account, Zapier will load a list of the documents in your Formstack Documents account. Go ahead and pick the invoice template that you just setup. Once you pick the document, Zapier is going to load a list of all the merge fields in your document.

For each of the merge fields in your document, you’ll need to match up the corresponding columns from your MySQL table. This tells Zapier how to send your data over to Formstack Documents so that it is populated in the correct spot in your template.

After you have matched up all of your merge fields, go ahead and save your Zap and turn it on. We’re ready for a test! Add a new row to your MySQL table and Zapier will detect the new row then send that data over to Formstack Documents. Formstack Documents will generate the invoice and email it to you.

Here’s what our merged invoice looked like:

Congrats, you’re all finished! You can now automatically generate all kinds of documents with data from your MySQL databases. Can you think of any other ways that you can use Formstack Documents to simplify your paperwork process?


Formstack '23 Fall Release: Your Questions Answered

We’ve compiled answers to commonly asked questions during the Fall ‘23 Release webinar.
Read more
Formstack is a SaaS company with a mission to help organizations digitize what matters, automate workflows, and fix processes—all without code. A variety of team members come together to compile posts under Formstack's authorship.
More Articles