This demo uses the DevExpress Word Processing Document API to change page setup parameters. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Specify the page orientation and size in the panel below. The Page Settings section allows you to set page margins and offset. Use the Apply Page Settings and Save as... dropdown button to select the output format, apply changes, and download the result.
using DevExpress.Drawing.Printing;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
void SetPaperSizeAndOrientation(Document document, Section section, DXPaperKind paperKind, float customPageWidth, float customPageHeight, bool isLandscape) {
document.Unit = DevExpress.Office.DocumentUnit.Inch;
section.Page.PaperKind = paperKind;
if (paperKind == DXPaperKind.Custom) {
section.Page.Width = customPageWidth;
section.Page.Height = customPageHeight;
}
section.Page.Landscape = isLandscape;
}
void SetMargins(Document document, Section section, float leftMargin, float rightMargin, float topMargin, float bottomMargin, bool mirroredMargins) {
document.Unit = DevExpress.Office.DocumentUnit.Inch;
section.Margins.Top = topMargin;
section.Margins.Bottom = bottomMargin;
section.Margins.Left = leftMargin;
section.Margins.Right = rightMargin;
document.MarginType = mirroredMargins ? MarginType.Mirrored : MarginType.Normal;
}
void SetHeaderFooterOffsets(Document document, Section section, float headerOffset, float footerOffset) {
document.Unit = DevExpress.Office.DocumentUnit.Inch;
section.Margins.HeaderOffset = headerOffset;
section.Margins.FooterOffset = footerOffset;
}
void SetGutterSettings(Document document, Section section, bool isGutterAtTop, GutterPosition gutterPosition, float gutter) {
document.Unit = DevExpress.Office.DocumentUnit.Inch;
section.Margins.GutterPosition = gutterPosition;
section.Margins.Gutter = gutter;
document.GutterAtTop = isGutterAtTop;
}