Page Break is used to start with contents in new page. Generally speaking, page break will be inserted automatically when one page are filled with text. Also, people can insert page break manually. For example, if we want to present title and subtitle in the first page and present body in the second body, we should insert a page break after typing the title.
In this post, I want to introduce the method about how to insert page break in Word with Silverlight. I prepare a document and want to insert a page break after paragraph 1. Also, the component, Spire.Doc for Silverlight is used in this example. Therefore, if you want to use the following code, please DOWNLOAD and install this component. Then, add its dll file as reference in your project.
Step 1. Design UserControl
Rename MainPage.xaml as InsertPageBreak.xaml. Double click it to design UserControl. Set background as an image. And then, add a label. Change label contents and set contents format. Finally, add a button to run.
Step 2. Declare SaveFileDialog
Declare a SaveFileDialog at the beginning to save document. Then, set a filter for this SaveFileDialog. The filter is used for users to choose the most appropriate document format. In this example, I just set filter format as .docx.
Step 3. Load Document
Right click project name to add existed item which is the document I want to insert page break. After adding, change the document Build Action as Embedded Resource.
Then, double click run button to write code. Declare a new document at first. Then, use foreach sentence to get document name from assembly. If the document name is the same as name of embedded resource, load this document.
Step 4. Insert Page Break
Because I want to insert page break after paragraph 1, so I need to get this paragraph in document section. Then, use paragraph.AppendBreak() method to insert break. The parameter passed to this method is break type. In this example, the type is PageBreak.
Note: because title is also taken as one paragraph, so the paragraph 1 in document becomes paragraph 2 when coding.
Step 5. Save Document
Judge if the SaveFileDialog which is declared in first step can pop up. If the result is true, save the document which we have inserted page break by using it.
public partial class MainPage : UserControl
private SaveFileDialog saveFileDialog= new SaveFileDialog();
this.saveFileDialog.Filter = “Word Document (*.docx)|*.docx”;
private void button1_Click(object sender, RoutedEventArgs e)
Document document = new Document();
Assembly assembly = this.GetType().Assembly;
foreach (String name in assembly.GetManifestResourceNames())
if (name.EndsWith(“Blues Introduction.docx”))
using (Stream docStream = assembly.GetManifestResourceStream(name))
document = new Document(docStream, FileFormat.Docx);
//Insert Page Break
Section section = document.Sections;
Paragraph paragraph = section.Paragraphs;
bool? result = this.saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
using (Stream stream = this.saveFileDialog.OpenFile())
Document with Page Break
Learn More about Silverlight Word Component, Spire.Doc for Silverlight.