Aspose.Words

How-to: Control New Pages during Mail Merge

Question

Is it possible to create a new page in the document for each record in the data source when executing mail merge?

Conversely, is it possible to make sure all merged records appear continuously without page breaks?

Answers

Yes. There are different techniques depending upon whether you are using simple mail merge or mail merge with regions.

Controlling New Pages when Using Simple Mail Merge

In Microsoft Word, go to File / Page Setup / Layout. Select Section / Start from new page. Since the mail merge engine duplicates document content and the result is multiple document sections (one section per merged record), choosing this option will force Word to start every section from a new page.

Controlling New Pages when Using Mail Merge with Regions

If you use mail merge with regions, then the mail merge region is duplicated for each record. A mail merge region can include block level elements such as paragraphs, tables, table rows all inside a single section. You can control page breaks for each merged record in a number of ways:

·          Format the first paragraph in the region to have a page break before it using Format / Paragraph / Line and Page Breaks.

·          Insert a page break using Insert / Break in Microsoft Word at the end of the mail merge region.

When the MailMerge.RemoveEmptyParagraphs property is set to true any paragraphs which are empty or only contain TableStart or TableEnd merge fields are removed automatically during mail merge. In this situation if you are applying the techniques to such a paragraph then this will cause incorrect behavior as the paragraphs containing page breaks will be removed during mail merge.

To remedy this issue you can consider moving the content from the next paragraph onto the previous paragraph so it will not be removed during mail merge.