Wednesday, 19 January 2011 06:30

Insert Word Page Break in Document in C#, VB.NET

Written by  Administrator
Rate this item
(0 votes)

Word Page Break, a mark to present ending of one page and beginning of new page, can be inserted automatically when users fill one page with contents or manually at a specified location by users. This guide demonstrates an easy solution to insert page break to split one page contents into two pages in C#, VB.NET via Spire.Doc for .NET. The following screenshot shows result after inserting Word page break.

Word Page Breaks

Spire.Doc for .NET provides Paragraph.AppendBreak method with customers to insert break easily in Word. The overload, which should be passed to this method, is BreakType (enum-type). There are three break types offered by Spire.Doc for .NET, PageBreak, ColumnBreak and LineBreak. Download and install Spire.Doc for .NET and follow the code blow to insert Word page break behind the specified paragraph.

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

namespace WordBreak
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile(@"E:\Work\Documents\WordDocuments\.NET Framework.docx");

            document.Sections[0].Paragraphs[3].AppendBreak(BreakType.PageBreak);

            document.SaveToFile("PageBreak.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("PageBreak.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordBreak
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim document As New Document()
            document.LoadFromFile("E:\Work\Documents\WordDocuments\.NET Framework.docx")

            document.Sections(0).Paragraphs(3).AppendBreak(BreakType.PageBreak)

            document.SaveToFile("PageBreak.docx", FileFormat.Docx2010)
            System.Diagnostics.Process.Start("PageBreak.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, a professional Word component, enables developers/programmers perform a wide range of processing tasks, such as generate, write, modify and save for their customize .NET, Silverlight and WPF applications.

Additional Info

  • tutorial_title: Insert Word Page Break
Last modified on Monday, 14 July 2014 05:59