Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Page orientation
The following example shows you how to set page orientation.
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(); PageMargins margins = new PageMargins(); margins.Bottom = 1440; // 1 inch margins.Left = 1440; // 1 inch margins.Right = 1440; // 1 inch margins.Top = 1440; // 1 inch margins.Footer = 720; // 1/2 inch margins.Header = 720; // 1/2 inch PageSize pageSize = new PageSize(12240, 15840); //8.5 x 11 inch pageSize.PageOrientation = PageOrientation.Landscape; Section section = new Section(); section.PageSize = pageSize; section.PageMargins = margins; doc.Body.Section = section; Run run = new Run(); run.AddText("Page size is 8.5 x 11 inch (Letter)."); Paragraph paragraph = new Paragraph(); paragraph.Add(run); 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() Dim margins As New PageMargins() margins.Bottom = 1440 ' 1 inch margins.Left = 1440 ' 1 inch margins.Right = 1440 ' 1 inch margins.Top = 1440 ' 1 inch margins.Footer = 720 ' 1/2 inch margins.Header = 720 ' 1/2 inch Dim pageSize As New PageSize(12240, 15840) '8.5 x 11 inch pageSize.PageOrientation = PageOrientation.Landscape Dim section As New Section() section.PageSize = pageSize section.PageMargins = margins doc.Body.Section = section Dim run As New Run() run.AddText("Page size is 8.5 x 11 inch (Letter).") Dim paragraph As New Paragraph() paragraph.Add(run) doc.Body.Add(paragraph) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*