Skip to main content

Helpcenter

Word Paging Features

The Word paging features are easy to use but Word only has basic paging features.

Word Paging Exercise
  1. Open word_paging.docx in the DocxFactory/exercises/templates/ directory (see picture below).

    image62.png
  2. Mark the table rows from the first table row to the column labels (including the column labels) in the Account item as Repeat Header so they will be repeated for every page.

    Because you can only have one level of repeating headers in the Word paging features, you can either mark the report header and the column labels or only the column labels as Repeat Header.

    Highlight the table rows from the first table row to the column labels (including the column labels) in the Account item and select the Repeat Header Rows in the Layout ribbon (see picture below).

    image63.png
  3. Chain the table rows of the Withdraw, Deposit and Summary items using Keep with next so the table rows cannot be split across pages and must stay whole.

    Highlight the first table row of the Withdraw and Deposit line items and the first 3 table rows of the Summary item, open the Paragraph dialog box in the Home ribbon and select Keep with next in the Line and Page Breaks tab (see picture below).

    image64.png
  4. Select the Keep lines together for the Comment item so the paragraph lines cannot be split across pages and must stay whole.

    Highlight the comment item, open the Paragraph dialog box in the Home ribbon and select Keep lines together in the Line and Page Breaks tab (see picture below).

    image65.png

The exercise introduces the most common Word paging features.

Repeat Header Rows

If a table overflows onto the next pages then the top table rows marked as repeat header will repeat when continuing in the next pages.

Note: The repeat header rows must start from the first table row. If you want to start the repeat header after the first table row then you will need to split the table where the repeat header starts.

Note: Repeat header does not work for nested tables, which means there can only be one level of repeat header rows for the top level table starting at the first table row, which greatly limits its possible uses.

Keep with Next

Keep with next says that the paragraph cannot be separated from the next paragraph so if the next paragraph does not fit in the page and is moved to the next page then it takes the paragraph with it.

Keep with next is mostly used to chain multiple paragraphs or table rows (using the paragraphs in the table row) to a single unit that cannot be separated so either all of them fit in the page or they are all moved together to the next page.

The paragraphs are chained together by marking all the paragraphs keep with next except for the last paragraph to stop the chaining.

Keep Lines Together

Keep lines together says that the paragraph cannot be split into lines so either the paragraph fits in the page or the entire paragraph is moved to the next page.

Keep lines together only works on a single paragraph and cannot be used to keep multiple paragraphs or table rows together, use keep with next for that.

Note: Keep lines together is completely ignored and has no effect in table rows, which greatly limits its possible uses.

Allow row to break across pages

Another important paging feature especially for rows with a height of several lines is Allow row to break across pages in the Row tab, in the Table Properties dialog box.

If Allow row to break across pages is not selected then the row and its content cannot be split across pages and either the entire row fits in the page or it is moved to the next page.

  1. Compile the template.

  2. Create the .DOCX file.

    Copy and run the code below.

using System;

using System.Diagnostics;

using DocxFactory;

public class Runme

{

public static void Main()

{

try

{

var stopwatch = Stopwatch.StartNew();

WordProcessingMerger.Load(

"C:/Program Files/DocxFactory/exercises/templates/word_paging.dfw");

WordProcessingMerger.Paste("Account");

for (int i = 0; i < 10; i++)

{

WordProcessingMerger.Paste("Withdraw");

}

for (int i = 0; i < 9; i++)

{

WordProcessingMerger.Paste("Deposit");

}

WordProcessingMerger.Paste("Total");

WordProcessingMerger.Paste("Summary");

for (int i = 0; i < 3; i++)

{

WordProcessingMerger.SetClipboardValue("Comment", "Comment",

"CommentLine1\n" +

"CommentLine2\n" +

"CommentLine3\n" +

"CommentLine4\n" +

"CommentLine5");

WordProcessingMerger.Paste("Comment");

}

WordProcessingMerger.Save("C:/temp/word_paging.docx");

Console.WriteLine(

"Completed (in {0:F3} seconds).",

(double) stopwatch.ElapsedMilliseconds / 1000);

}

catch (Exception e)

{

Console.WriteLine(e);

}

}

}

  1. Open the created .DOCX file (see picture below).

    You can change the number of line items, number of comments etc. in the code and recreate the new document to see how the report is divided into pages.

    image66.png