Skip to main content
All docs
V25.1
  • DocumentExportElementStyle.TextAlignment Property

    Specifies the element’s text alignment.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public TextAlignment TextAlignment { get; set; }

    Property Value

    Type Description
    TextAlignment

    An enumeration value.

    Available values:

    Show 12 items
    Name Description
    TopLeft

    The text is vertically aligned at the top, and horizontally aligned on the left.

    TopCenter

    The text is vertically aligned at the top, and horizontally aligned at the center.

    TopRight

    The text is vertically aligned at the top, and horizontally aligned on the right.

    MiddleLeft

    The text is vertically aligned in the middle, and horizontally aligned on the left.

    MiddleCenter

    The text is vertically aligned in the middle, and horizontally aligned at the center.

    MiddleRight

    The text is vertically aligned in the middle, and horizontally aligned on the right.

    BottomLeft

    The text is vertically aligned at the bottom, and horizontally aligned on the left.

    BottomCenter

    The text is vertically aligned at the bottom, and horizontally aligned at the center.

    BottomRight

    The text is vertically aligned at the bottom, and horizontally aligned on the right.

    TopJustify

    The text is vertically aligned at the top, and horizontally justified.

    This mode is ignored in Silverlight applications.

    MiddleJustify

    The text is vertically aligned in the middle, and horizontally justified.

    This mode is ignored in Silverlight applications.

    BottomJustify

    The text is vertically aligned at the bottom, and horizontally justified.

    This mode is ignored in Silverlight applications.

    Remarks

    The PDF export engine applies different formatting to document elements for visual clarity. For instance, it applies the bold font attribute to column captions and colors them gray. The image below displays standard document formatting:

    PDF Export - Standard Formatting

    You can use PDF export options to customize document appearance. Style options are applied in the following order:

    1. Style settings that you assign to the DefaultElementStyle property in the CustomizeDocument event handler. These settings affect all elements: table cells, document/page headers and footers.

    2. The export engine’s style settings.

    3. Style settings that you assign to the DataCellStyle property in the CustomizeColumn event handler. These settings affect all data cells in the corresponding column.

    4. Style settings that you assign to the ElementStyle property in the following event handlers:

      • CustomizeCell
      • CustomizeDocumentFooter
      • CustomizeDocumentHeader
      • CustomizePageFooter
      • CustomizePageHeader

      These settings affect only the corresponding elements.

    Note

    Styles applied later have higher priority. For instance, export engine styles override DefaultElementStyle settings.

    Specify the TextAlignment property to change an element’s text alignment.

    Grid Example

    The following example customizes exported document appearance:

    @rendermode InteractiveServer
    @using DevExpress.Drawing;
    @inject WeatherForecastService ForecastService
    
    <DxGrid @ref="Grid" Data="@forecasts">
        <Columns>
            <DxGridDataColumn Caption="Date" FieldName="Date" />
            <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" />
            <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" />
            <DxGridDataColumn Caption="Summary" FieldName="Summary" />
        </Columns>
        <ToolbarTemplate>
            <DxToolbar>
                <DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
            </DxToolbar>
        </ToolbarTemplate>
    </DxGrid>
    
    @code {
        IGrid Grid;
        private WeatherForecast[]? forecasts;
    
        protected override async Task OnInitializedAsync() {
            forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
        }
        async Task ExportPdf_Click() {
            await Grid.ExportToPdfAsync("ExportResult", new GridPdfExportOptions() {
                CustomizeCell = OnCustomizeCell, // Customizes table cell appearance
                CustomizeDocument = OnCustomizeDocument, // Customizes overall document appearance
                CustomizeDocumentHeader = OnCustomizeDocumentHeader, // Adds and customizes a document header
            });
        }
        void OnCustomizeDocument(GridDocumentExportCustomizeDocumentEventArgs args) {
            // Sets default font settings for all elements
            args.DefaultElementStyle.Font = new DXFont("Times New Roman", 14, DXFontStyle.Regular);
        }
        void OnCustomizeCell(GridDocumentExportCustomizeCellEventArgs args) {
            // Sets border settings for all table cells
            args.ElementStyle.BorderColor = System.Drawing.Color.MediumBlue;
            args.ElementStyle.BorderWidth = 3;
            args.ElementStyle.BorderDashStyle = DevExpress.XtraPrinting.BorderDashStyle.Dash;
            // Sets style settings for header cells
            if(args.AreaType == DocumentExportAreaType.Header) {
                args.ElementStyle.BackColor = System.Drawing.Color.DimGray;
                args.ElementStyle.BorderSides = DevExpress.XtraPrinting.BorderSide.None;
                args.ElementStyle.ForeColor = System.Drawing.Color.White;
            }
            args.Handled = true;
        }
        void OnCustomizeDocumentHeader(GridDocumentExportCustomizeDocumentHeaderFooterEventArgs args) {
            // Adds a document header
            args.Text = "Weather Forecast";
            // Sets header style settings
            args.ElementStyle.Font = new DXFont("Arial", 16, DXFontStyle.Bold);
            args.ElementStyle.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0);
            args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
        }
    }
    

    TreeList Example

    The following example customizes exported document appearance:

    @rendermode InteractiveServer
    @using DevExpress.Drawing
    @inject SpaceObjectDataProvider SpaceObjectDataProvider
    
    <DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites">
        <Columns>
            <DxTreeListDataColumn FieldName="Name" />
            <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
            <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" />
            <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2"/>
        </Columns>
        <ToolbarTemplate>
            <DxToolbar>
                <DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
            </DxToolbar>
        </ToolbarTemplate>
    </DxTreeList>
    
    @code {
        ITreeList TreeList { get; set; }
        object TreeListData { get; set; }
    
        protected override async Task OnInitializedAsync() {
            TreeListData = SpaceObjectDataProvider.GenerateData();
        }
        async Task ExportPdf_Click() {
            await TreeList.ExportToPdfAsync("ExportResult", new TreeListPdfExportOptions() {
                CustomizeCell = OnCustomizeCell, // Customizes table cell appearance
                CustomizeDocument = OnCustomizeDocument, // Customizes overall document appearance
                CustomizeDocumentHeader = OnCustomizeDocumentHeader, // Adds and customizes a document header
            });
        }
        void OnCustomizeDocument(TreeListDocumentExportCustomizeDocumentEventArgs args) {
            // Sets default font settings for all elements
            args.DefaultElementStyle.Font = new DXFont("Times New Roman", 14, DXFontStyle.Regular);
        }
        void OnCustomizeCell(TreeListDocumentExportCustomizeCellEventArgs args) {
            // Sets border settings for all table cells
            args.ElementStyle.BorderColor = System.Drawing.Color.MediumBlue;
            args.ElementStyle.BorderWidth = 3;
            args.ElementStyle.BorderDashStyle = DevExpress.XtraPrinting.BorderDashStyle.Dash;
            // Sets style settings for header cells
            if (args.AreaType == DocumentExportAreaType.Header) {
                args.ElementStyle.BackColor = System.Drawing.Color.DimGray;
                args.ElementStyle.BorderSides = DevExpress.XtraPrinting.BorderSide.None;
                args.ElementStyle.ForeColor = System.Drawing.Color.White;
            }
            args.Handled = true;
        }
        void OnCustomizeDocumentHeader(TreeListDocumentExportCustomizeDocumentHeaderFooterEventArgs args) {
            // Adds a document header
            args.Text = "Space Objects";
            // Sets header style settings
            args.ElementStyle.Font = new DXFont("Arial", 16, DXFontStyle.Bold);
            args.ElementStyle.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0);
            args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
        }
    }
    
    See Also