Data merge enables you to create versions of an Affinity Publisher document in which portions of content are replaced by data from a data merge source (herein referred to as a data source for brevity).
Common uses of data merge include print runs of business cards and personalised mailouts, and its power also quickly progresses more ambitious projects like catalogues and brochures.
This article will give you practical experience of using data merge. All the necessary files are provided for you.
How data merge works
A few steps need to be taken so that Affinity Publisher knows where you want it to insert data, which can be text and pictures.
To prepare an Affinity Publisher document for data merge:
- Ideally, design the document with data merge in mind from the start. Throughout this article, you’ll learn considerations to make.
- Connect a data source to the document. It can be in one of several specially formatted (yet common) file formats.
- Insert fields from the data source into the document. You’ll be familiar with fields already if you have ever told Affinity Publisher to automatically add page numbers to a document, for example.
You can then generate a new data-merged document, which repeats the original document’s pages as many times as necessary to display the data source’s records.
Learn the fundamentals with business cards
Among the unpacked practice files, open the Business card folder.
The business-card.afpub file contains a single page for a one-sided card design. It needs to be prepared for data merge as described a moment ago.
Open employees.csv in a text editor, such as TextEdit (Mac) or Notepad (Win). Data sources tend to be machine-generated rather than hand-typed, but it’s helpful to understand the CSV (comma-separated values) format used here.
- The first line lists the names of fields. These will be displayed in Affinity Publisher’s Fields Panel.
- A delimiter indicates the end of one field and the start of another. We’ve used a comma because it isn’t needed in any record values—see tip below.
- Subsequent lines contain records. In this project, there is a record for each person who needs a business card.
- Records are made up of values, which are separated by the same delimiter used in the first line. It is these values that will be merged with your document design.
- Field names and values may optionally be surrounded by quotation marks. However, there should not be spaces between them.
- An individual record does not have to contain a value for every field. In this data source, not everyone has a telephone number, which is indicated by two quotes with nothing between them.
- A carriage return at the end of a line marks the end of a record.
- The last line can contain a record or a blank line. Affinity Publisher will simply ignore the latter.
Close the data source.
Connect the data source
Return to the business card document in Affinity Publisher.
- Select Document > Data Merge Manager.
- At the bottom left of the manager, select Add Data Merge Source.
- Browse to and open the employees.csv file.
In the manager’s Source section, the default Delimiter and Quote settings are correct for our data source. You’ll use the manager further in a moment but, for now, click Close.
Insert fields into the document
The document contains pre-styled text as placeholders for where an employee’s name, role and contact details will be displayed.
Replace the placeholders with fields from the data source.
- Select View > Studio > Fields to open the Fields Panel.
- On the panel, expand the section labelled Data Merge - employees.csv.
- For each placeholder in turn:
- Select all of its text.
- On the Fields Panel, double-click the corresponding field to replace the selection with it.
Preview the data merge
Use the Data Merge Manager’s Preview section to check, one record at a time, that the real data fits well in your design.
This means you needn’t generate a data-merged document and scroll through its pages, which might take a while for a large data source—especially one that places images into picture frames.
Does any record’s text—a long name, say—overflow its frame or cause surrounding text to reflow in an unanticipated way?
If many records do not fit the design, amend the document before proceeding with data merge. You might do so even if there are just a few issues.
Generated documents are editable, though, so you can make changes in isolation when absolutely necessary. For example, you might not want to reduce a font size universally if only a few records need it.
Generate a data-merged document
The Data Merge Manager’s Filter section enables a subset of a data source’s records to be processed. This is a useful option but we’ll stick with the All Records setting in this article.
Click Generate to proceed with the data merge. Soon, you’ll see a new document in which each page is a different person’s business card, ready to export a PDF file for client approval and send to a printing service.
Using data merge layouts
With the technique you’ve learned so far, each generated variation of your original document’s pages contains data from a single record.
In publications like catalogues and brochures, a single page might need to display data from multiple records. To achieve this, you’ll use Affinity Publisher’s Data Merge Layout Tool.
A data merge layout is a table-like structure in which objects added to the top-left cell are repeated in all other cells.
For hands-on experience of this, do the following:
- Create a new document that contains two facing pages.
- Select the Data Merge Layout Tool.
- On the left page, draw a data merge layout that fills the page to its margins. Keep the layout selected.
- Use the Ellipse Tool to draw a circle within the layout’s top-left cell. The shape is automatically repeated in all other cells.
Note that the top-left cell can contain multiple objects, including text objects that contain fields.
The power of data merge layouts
Think back to the business card example. For each record in the data source, a copy of the original document’s page was generated in the data-merged document.
Let’s say you inserted a second instance of a field, either on the existing page or a second one (for a double-sided card design). Each generated page, or group of two pages, would display the corresponding value from a single record in both places.
What’s special about data merge layouts is that each cell is populated with data from a different record.
Also, you’ll soon see that each data merge layout in a document needn’t use the same visual design or display the same number of columns and rows.
Let’s get more ambitious
From the practice files, look in the Catalogue folder and open catalogue.afpub. The picture frame and text frame on its left page need to repeat in columns and rows across both pages.
To ensure the document is connected to the data source, open the Data Merge Manager, click Select, browse to the Catalogue folder and open products.tsv.
Previously, you selected a data merge layout and drew objects directly into it. Objects can be included in a layout even if they were drawn outside of it, so let’s see how this is done:
- On the left page, draw a data merge layout that fills the page to its margins.
- On the context toolbar, set Columns to 2, Rows to 3, and Gutter to 1.5mm.
- Deselect the data merge layout. (This is just to emphasise the point.)
- On the Layers Panel, select the picture and text frames’ layers.
- Drag the layers to the bottom of the data merge layout’s layer and then slightly to the right, and drop them when an insertion point appears.
You have established a parent-child relationship between the data merge layout and both frames, respectively.
Positioning objects within the top-left cell’s visual boundary is important, but it’s this relationship that tells Affinity Publisher to repeat them in all of a data merge layout’s cells.
How data flows into data merge layouts
Duplicate the data merge layout in the equivalent position on the right page. Your document should now look like this:
The Data Merge Manager is automatically aware of all the data merge layouts in a document. So, unlike linking text frames to specify how text flows through them, you don’t need to do the same for data merge layouts.
The manager uses the number of cells in all of the layouts to calculate how many times it needs to repeat the original document’s pages.
When there are insufficient records to populate all of the cells in the repeated pages, the objects repeated in those cells are simply deleted, leaving white space on the last page or spread. Remember that generated documents are fully editable, enabling you to adapt the design in this situation.
Automatically placing images
Data merge works for images as well as text. In the generated document shown above, the data source included references to externally stored images.
Inserting a field into a picture frame is simple. Select a picture frame and then double-click the relevant field on the Fields Panel. A photo-like icon indicates a picture frame contains a field.
Your workflow might address image composition with data merge and picture frame dimensions in mind. If not, check generated documents and resize pictures within their frames as necessary.
Get creative with data merge layouts
From the practice files, open catalogue-2.afpub and, like earlier, use the Data Merge Manager to ensure it is connected to the products.tsv data source.
Earlier, we mentioned that each data merge layout in a document can have different settings. Compare the presentation of the data merge layouts on pages 1 and 2 of this document.
On Page 1, the large picture frame is intended to display a single image of multiple catalogue items. It is independent of the data merge layout, which doesn’t display any picture frames—unlike the data merge layout on Page 2.
The Data Merge Manager will ignore Page 1’s picture frame, so a picture has to be manually placed in it.
Explore the other pages of the document to see how differently they incorporate data merge layouts.
When you first drew a data merge layout, its table-like look might have seemed uninspiringly rigid. By now, though, you can see that data merge layouts can be used in practical and creative ways.