Mail Merge with QuarkXPress

You need to send out a letter to your customers, which is personalized? Or you have a client that needs you to create a template to send out hundreds of personalized letters?

This task becomes time-consuming once you have several hundred addresses and you want each letter to use different content, such as text and pictures. Often, this requirement is described as mail merge.

With QuarkXPress 2018 and a sample JavaScript this is easily done:

Mail Merge using a simple JavaScript in QuarkXPress 2018

QuarkXPress 2018 offers a sample script that solves this simple mail merge problem and you are done in a few minutes. If you have more complex scenarios, feel free to modify and enhance the sample JavaScript, its code is open.

Step 1: Define you data

Define your data, either by using spreadsheet (e.g. Microsoft Excel), a database or a simple text editor.

You can use images and text. In the sample script we use one image per letter and several fields, like name, salutation, subject and greeting.

First, in the first row define the names of the fields. You can use any name for your field names, it is better for troubleshooting if you use self-explanatory names.

In our example we use:

URIRecipients NameAddress line 1Address line 2StateZIP CodeSubjectSenders NameSenders Title

Then, starting in the second row you enter the data:

URIRecipients NameAddress line 1Address line 2StateZIP CodeSubjectSenders NameSenders Title
Images\photo1.pngPeter PersonPenthouse 1Some LanePrime CityPA 12345Did you know?Marvin the MartianSVP Technology
Images\photo2.pngMatthew Manand so on…
and so on…

Of course you can also just use a text editor like Atom or TextEdit.

Now we need the data as a CSV (comma-separated values) file. You can use different separators, tabs, commas, semicolons, just make sure that you always use the same one to separate data. If you used MS Excel to create your data, you can save as CSV and specify your separator. Make sure that you do not use a separator that’s within your data.

In our example we are going to use a comma:

URI,Recipients Name,Address line 1,Address line 2,State, ZIP Code,Subject,Senders Name,Senders Title
Images\photo1.png,Peter Person,Penthouse 1,Some Lane,Prime City,PA 12345,Did you know?,Marvin the Martian,SVP Technology
Images\photo2.png,Matthew Man,Mansion 1,Some other Lane,Metro,MA 67890,Act now!,Alberto the larger Martian,SVP Technology
Images\photo3.png,Rudi Random,Residence 1,Yet Another Lane,Rural area,RA 11111,Surprising offer!,Easter the Egg,SVP Technology

Step 2: Create a template

Now in QuarkXPress 2018 create a template, so just a QuarkXPress document with your letter.

Whenever you have variable data (the address, the image) make sure that you put these boxes, text box or picture box, on a master page.

You can find the sample template (qpt file) here: https://github.com/qxpjs/Mail-merge/tree/master/mailmerge-data

Step 3: Insert placeholders

Wherever you need variable data, e.g. the personalized subject line, don’t type the data. Instead, type the field name (header name) that you used in the CSV file, surrounded by two brackets.

In our example type:

Subject: <<Subject>>

So the first word “Subject” will appear like this in your final output. The word “<<Subject>>” will be replaced by the data.

Of course you could also just use the placeholder by itself:

<<Subject>>

As this is just text, style it manually or use style sheets for the placeholder.

Step 4: Run the script

This “mail merge” script is contained with QuarkXPress 2018 as a script.

Open your “JavaScript” palette (Window menu). Navigate to to the Samples folder (in the JavaScript palette) and then to the “Automation” folder.

Double click the “Mail Merge.js” or select it and click on the Run button.

QuarkXPress will now create pages, one for each record defined in your CSV file.

Please note that QuarkXPress has a limitation of 2000 pages per layout, so if you have more records, first split the data to chunks of not more than 2000.

Step 5: Export PDF

You can now either print the layout containing all pages (or create one large PDF).

Alternatively you can create one PDF per page, by choosing the appropriate output option “Export pages as separate PDFs” in the PDF Export dialog:

Quick video showing this example


More sample JavaScripts for QuarkXPress on github

Quark has created a page on github to share more sample scripts and to encourage users to share their scripts:

https://github.com/qxpjs


 

Both an engineer and a layout artist, Matthias bridges the gap between technology and people.

Before joining Quark, Matthias pioneered print, Web, and multimedia products for multiple German publishing companies. Since 1997 he has played a central role in shaping Quark’s desktop and enterprise software.
Starting 2003 Matthias has focused on Quark’s interactive and digital publishing solutions. He is an active participant in design and publishing communities and represents Quark in the Ghent PDF Workgroup.

Since February 2014 Matthias heads Quark’s Desktop Publishing business unit and is therefore responsible for QuarkXPress.