Back to Devexpress

How to: Configure the Page Layout Programmatically

officefileapi-116855-word-processing-document-api-examples-layout-how-to-configure-the-page-layout-programmatically.md

latest1.7 KB
Original Source

How to: Configure the Page Layout Programmatically

  • Sep 19, 2023

This example illustrates how to adjust page settings in code.

The page layout settings in the API pertain to the document’s section. Therefore, you need to change the SectionPage properties to adjust page settings.

The following code sample specifies page layout settings for the first section of the document: the A6 paper in landscape orientation with the left margin set to two inches.

View Example

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Drawing.Printing;
using DevExpress.Utils;

using (var wordProcessor = new RichEditDocumentServer()) {

    wordProcessor.LoadDocument("Documents\\Grimm.docx");
    Document document = wordProcessor.Document;

    document.Sections[0].Page.PaperKind = DXPaperKind.A6;
    document.Sections[0].Page.Landscape = true;
    document.Sections[0].Margins.Left = Units.InchesToDocumentsF(2.0f);
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Drawing.Printing
Imports DevExpress.Utils

Using wordProcessor = New RichEditDocumentServer()
    wordProcessor.LoadDocument("Documents\Grimm.docx")
    Dim document As Document = wordProcessor.Document

    document.Sections(0).Page.PaperKind = DXPaperKind.A6
    document.Sections(0).Page.Landscape = True
    document.Sections(0).Margins.Left = Units.InchesToDocumentsF(2.0F)
End Using