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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/aspxrichedit-how-to-define-the-default-page-settings-such-as-margins-paper-kind-etc-t520406
using DevExpress.XtraRichEdit;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
NewDocument();
}
private void NewDocument()
{
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 memoryStream = new MemoryStream();
server.SaveDocument(memoryStream, DocumentFormat.Rtf);
ASPxRichEdit1.Open("document" + Guid.NewGuid().ToString(), DocumentFormat.Rtf, () => { return memoryStream.ToArray(); });
}
}