Independentsoft
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Page borders
The following example shows you how to add borders around the page.
C# example
using System; using Independentsoft.Office.Word; using Independentsoft.Office.Word.Sections; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); // Create content Run run = new Run(); run.AddText("This page has a decorative border around it."); Paragraph paragraph = new Paragraph(); paragraph.Add(run); // Create page borders string borderColor = "0000FF"; // Blue int borderWidth = 12; TopBorder topBorder = new TopBorder(); topBorder.Style = StandardBorderStyle.DoubleLine; topBorder.Color = borderColor; topBorder.Width = borderWidth; BottomBorder bottomBorder = new BottomBorder(); bottomBorder.Style = StandardBorderStyle.DoubleLine; bottomBorder.Color = borderColor; bottomBorder.Width = borderWidth; LeftBorder leftBorder = new LeftBorder(); leftBorder.Style = StandardBorderStyle.DoubleLine; leftBorder.Color = borderColor; leftBorder.Width = borderWidth; RightBorder rightBorder = new RightBorder(); rightBorder.Style = StandardBorderStyle.DoubleLine; rightBorder.Color = borderColor; rightBorder.Width = borderWidth; PageBorders pageBorders = new PageBorders(); pageBorders.TopBorder = topBorder; pageBorders.BottomBorder = bottomBorder; pageBorders.LeftBorder = leftBorder; pageBorders.RightBorder = rightBorder; Section section = new Section(); section.PageBorders = pageBorders; paragraph.Section = section; doc.Body.Add(paragraph); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Imports Independentsoft.Office.Word.Sections Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() ' Create content Dim run As Run = New Run() run.AddText("This page has a decorative border around it.") Dim paragraph As Paragraph = New Paragraph() paragraph.Add(run) ' Create page borders Dim borderColor As String = "0000FF" ' Blue Dim borderWidth As Integer = 12 Dim topBorder As TopBorder = New TopBorder() topBorder.Style = StandardBorderStyle.DoubleLine topBorder.Color = borderColor topBorder.Width = borderWidth Dim bottomBorder As BottomBorder = New BottomBorder() bottomBorder.Style = StandardBorderStyle.DoubleLine bottomBorder.Color = borderColor bottomBorder.Width = borderWidth Dim leftBorder As LeftBorder = New LeftBorder() leftBorder.Style = StandardBorderStyle.DoubleLine leftBorder.Color = borderColor leftBorder.Width = borderWidth Dim rightBorder As RightBorder = New RightBorder() rightBorder.Style = StandardBorderStyle.DoubleLine rightBorder.Color = borderColor rightBorder.Width = borderWidth Dim pageBorders As PageBorders = New PageBorders() pageBorders.TopBorder = topBorder pageBorders.BottomBorder = bottomBorder pageBorders.LeftBorder = leftBorder pageBorders.RightBorder = rightBorder Dim section As Section = New Section() section.PageBorders = pageBorders paragraph.Section = section doc.Body.Add(paragraph) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*