Forums

Overview » VB .NET » Insert Page Break in Word
Reply

Insert Page Break in Word

Lemon Brown
Member



Since: 15 Sep 2011
Posts: 89
Posted 29 Jan 2012 02:56:33

In Word, page break is used to set location where is the ending in first page and beginning in second page. MS Word can insert page break automatically when words are filled with one page. Also, we can insert page break manually at the specified location. For example, I will insert a page break to separate title from body. The following code shows how to insert page break in Word with VB.NET via Spire.Doc.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace pagebreak
	Partial Public Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			'Create word document
			Dim document As New Document()
			document.LoadFromFile("D:\Sample.doc")

			InsertBreak(document)

			'Save doc file.
			document.SaveToFile("Sample.doc", FileFormat.Doc)

			'Launching the MS Word file.
			WordDocViewer("Sample.doc")

		End Sub
		Private Sub InsertBreak(ByVal document As Document)
			Dim section As Section = document.Sections(0)
			Dim paragraph As Paragraph = section.Paragraphs(2)
			paragraph.AppendBreak(BreakType.PageBreak)
		End Sub

		Private Sub WordDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub
	End Class
End Namespace

In Word, page break is used to set location where is the ending in first page and beginning in second page. MS Word can insert page break automatically when words are filled with one page. Also, we can insert page break manually at the specified location. For example, I will insert a page break to separate title from body. The following code shows how to insert page break in Word with VB.NET via Spire.Doc.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace pagebreak
	Partial Public Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			'Create word document
			Dim document As New Document()
			document.LoadFromFile("D:\Sample.doc")

			InsertBreak(document)

			'Save doc file.
			document.SaveToFile("Sample.doc", FileFormat.Doc)

			'Launching the MS Word file.
			WordDocViewer("Sample.doc")

		End Sub
		Private Sub InsertBreak(ByVal document As Document)
			Dim section As Section = document.Sections(0)
			Dim paragraph As Paragraph = section.Paragraphs(2)
			paragraph.AppendBreak(BreakType.PageBreak)
		End Sub

		Private Sub WordDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub
	End Class
End Namespace

Reply to this topic

Message
Reply
Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency