Skip to main content

How to: Define the default page settings such as margins, paper kind, landscape etc

  • 2 minutes to read

It’s possible to use the non-visual RichEditDocumentServer component to adjust the required document settings. Create a new document using RichEditDocumentServer and adjust its page by using the corresponding API.

Refer to the following documentation articles, where you can learn how to set the required properties: Document, DefaultCharacterProperties.

This example demonstrates how to set a document page’s landscape, paper kind, margins and font properties.

View Example

<dx:ASPxRichEdit ID="ASPxRichEdit1" runat="server" >
    <Settings>
        <Behavior CreateNew="Hidden" Save="Hidden" Open="Hidden" SaveAs="Hidden" />
    </Settings>
</dx:ASPxRichEdit>
using DevExpress.XtraRichEdit;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) {
         if (!IsPostBack)
            NewDocument();
    }

    private void NewDocument() {
        MemoryStream memoryStream = null;
        ASPxRichEdit1.Open("document" + Guid.NewGuid().ToString(), DocumentFormat.Rtf, () => { 
            RichEditDocumentServer server = new RichEditDocumentServer();
            server.Document.Sections[0].Page.Landscape = false;
            server.Document.Unit = DevExpress.Office.DocumentUnit.Millimeter;
            server.Document.Sections[0].Margins.Left = 0.5f;
            server.Document.Sections[0].Margins.Right = 0.5f;
            server.Document.Sections[0].Margins.Top = 0.5f;
            server.Document.Sections[0].Margins.Bottom = 0.5f;

            server.Document.DefaultCharacterProperties.FontName = "Arial";
            server.Document.DefaultCharacterProperties.FontSize = 12f;
            server.Document.DefaultCharacterProperties.ForeColor = Color.Red;

            server.Document.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.Custom;
            server.Document.Sections[0].Page.Width = 105f;
            server.Document.Sections[0].Page.Height = 297f;

            memoryStream = new MemoryStream();
            server.SaveDocument(memoryStream, DocumentFormat.Rtf);
            return memoryStream.ToArray();
        });
        if (memoryStream != null)
            memoryStream.Dispose();
    }
}