Document Templates Tip: Say No to Forced Page Breaks
This article explains why to avoid forced page breaks in document templates and how to create templates that automatically adjust to the content using other word processing features.

A forced page break in TX Text Control is a feature that allows you to manually insert a page break at a specific input position in a document. This forces the content following the break to begin on a new page, regardless of the natural flow of the text.
A forced page break can be added using the CTRL+ENTER key combination or programmatically using the following code.
textControl1.Selection.Text = "\f";
While this can be useful for creating documents quickly, it poses many problems when creating templates that are used to populate dynamic content. A template is a document that contains placeholders for dynamic content. When the template is loaded into TX Text Control, the placeholders are replaced with the actual content.
In the visual document editor of TX Text Control, the forced page break is displayed as a horizontal line. This is a visual indicator that a page break is inserted at this position.
Forced Page Breaks in Templates
Now consider a template where longer text is dynamically inserted into a merge field, followed by a forced page break. The following screenshot shows a template with a merge field and a forced page break inserted after it.
During the merge process, the merge field is replaced with the actual content. The forced page break is still present in the document, and the content is longer and breaks across pages. The following screenshot shows the result of the merge process.
Now, the forced page break is moved to the next page which results in an empty page. This is not the desired behavior when creating templates for dynamic content.
Avoiding Forced Page Breaks
When creating templates for dynamic content, it is important to avoid forced page breaks. Instead, use a paragraph setting that inserts a page break before the specified paragraph. Usually you want to start a new heading or chapter on a new page. In this case, use the "page break before" setting that can be defined for a paragraph.
This can be set in the Paragraph settings dialog.
Programmatically, this can be set using the following code snippet:
textControl1.Selection.ParagraphFormat.PageBreakBefore = true;
When this setting is added to a paragraph and the control characters are enabled, the setting is indicated by a small centered black dot at the beginning of the paragraph.
When merging dynamic content into a template, the defined chapter now always starts on a new page and no extra blank pages are accidentally added.
Use Stylesheets
When creating templates for dynamic content, it is recommended to use stylesheets to define the formatting of the content. This includes the paragraph settings such as the "page break before" setting. Stylesheets can be used to define the formatting of the content and the paragraph settings.
Programmatically, this can be set using the following code snippet:
TXTextControl.ParagraphStyle paragraphStyle = new TXTextControl.ParagraphStyle("Chapter");
paragraphStyle.ParagraphFormat.PageBreakBefore = true;
Conclusion
Forced page breaks are useful when creating documents manually, but they can cause issues when creating templates for dynamic content. It is recommended to use paragraph settings such as "page break before" to avoid empty pages when merging dynamic content into a template.
Stylesheets can be used to define the formatting of the content and the paragraph settings. This allows you to create templates that are used to populate dynamic content without the need for manual adjustments.
Related Posts
TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format
Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…
Expert Implementation Services for Legacy System Modernization
We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.
Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5
TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…