Insert Page Break in Word in WPF

2012-08-07 06:39:51 Written by  support iceblue
Rate this item
(0 votes)

Word Page Break is used to start with contents in a new page, which can be inserted anywhere in Word document. Generally speaking, page break can be generated automatically when one page is filled with contents, or users can specify where Microsoft Word positions automatic page break. Also, users can insert manual page breaks in document to keep some paragraphs together in a single page.

Spire.Doc for WPF, a professional WPF component on manipulating Word document, enables users to insert page break in Word with WPF. Users can invoke paragraph.Append(BreakType.PageBreak) method directly to insert page break in Word.

Spire.Doc presents an easy way to insert a page break. Just follow the simple steps below to insert a page break.

The following screenshot presents document before inserting page break.

Download and install Spire.Doc for WPF. Add button in MainWindow and double click this button to use the following code to insert page break with WPF in Word.

[C#]
using System.Windows;
using Spire.Doc;
using Spire.Doc.Documents;

namespace Doc_x_PageBreak
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\work\documents\Blues Introduction.docx");

            //Get Paragraph Position
            Section section = doc.Sections[0];
            Paragraph paragraph = section.Paragraphs[1];

            //Insert Page Break
            paragraph.AppendBreak(BreakType.PageBreak);

            //Save and Launch
            doc.SaveToFile("PageBreak.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("PageBreak.docx");
        }
    }
}
[VB.NET]
Imports System.Windows
Imports Spire.Doc
Imports Spire.Doc.Documents

Class MainWindow

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'Load Document
        Dim doc As New Document()
        doc.LoadFromFile("E:\work\documents\Blues Introduction.docx")

        'Get Paragraph Position
        Dim section As Section = doc.Sections(0)
        Dim paragraph As Paragraph = section.Paragraphs(1)

        'Insert Page Break
        paragraph.AppendBreak(BreakType.PageBreak)

        'Save and Launch
        doc.SaveToFile("PageBreak.docx", FileFormat.Docx)
        System.Diagnostics.Process.Start("PageBreak.docx")

    End Sub
End Class

Effective Screenshot:

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.

Additional Info

  • tutorial_title: Insert Page Break in WPF
Last modified on Friday, 24 September 2021 09:52