Back to Devexpress

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

aspnet-119371-components-rich-text-editor-examples-how-to-define-the-default-page-settings-such-as-margins-paper-kind-landscape-etc.md

latest4.1 KB
Original Source

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

  • Nov 29, 2023
  • 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

aspx
<dx:ASPxRichEdit ID="ASPxRichEdit1" runat="server" >
    <Settings>
        <Behavior CreateNew="Hidden" Save="Hidden" Open="Hidden" SaveAs="Hidden" />
    </Settings>
</dx:ASPxRichEdit>
csharp
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();
    }
}
vb
Imports DevExpress.XtraRichEdit

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
         If (Not IsPostBack) Then
            NewDocument()
         End If
    End Sub

    Private Sub NewDocument()
        Dim server As 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

        Dim memoryStream As New MemoryStream()
        server.SaveDocument(memoryStream, DocumentFormat.Rtf)
        ASPxRichEdit1.Open("document" & Guid.NewGuid().ToString(), DocumentFormat.Rtf, Function() memoryStream.ToArray())
    End Sub
End Class