Skip to main content
All docs
V25.1
  • GridDocumentExportCustomizeDocumentEventArgsBase.Margins Property

    Specifies page margins for the exported document (in hundredths of an inch).

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public DXMargins Margins { get; set; }

    Property Value

    Type Description
    DXMargins

    An object that stores page margins in hundredths of an inch.

    Remarks

    When exporting Grid or TreeList data to PDF, handle the CustomizeDocument event to configure style and page settings for the output document. Use the Margins event argument to change exported document margins.

    Note

    Page headers and footers are located within top and bottom margins. To ensure correct document rendering, set the top/bottom margin to a value greater than the header/footer content height (including top and bottom paddings).

    Grid Example

    The following example exports Grid data to PDF and customizes output 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() {
                CustomizeDocument = OnCustomizeDocument, // Customizes exported document appearance
                CustomizePageHeader = args => args.Text = "Weather Forecast", // Adds a page header
                CustomizePageFooter = args => args.Text = "Page {0} of {1}", // Adds a page footer
            });
        }
        void OnCustomizeDocument(GridDocumentExportCustomizeDocumentEventArgs args) {
            // Sets default font settings for all elements in the exported document
            args.DefaultElementStyle.Font = new DXFont("Times New Roman", 12, DXFontStyle.Regular);
            // Switches the page orientation to landscape
            args.Landscape = true;
            // Sets page margins to 0.5 inches
            args.Margins = new DXMargins(50, 50, 50, 50);
            // Sets the page size to a custom value (width: 6 inches, height: 8 inches)
            args.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.Custom;
            args.PageSize = new System.Drawing.Size(600, 800);
        }
    }
    

    TreeList Example

    The following example exports TreeList data to PDF and customizes output 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() {
                CustomizeDocument = OnCustomizeDocument, // Customizes exported document appearance
                CustomizePageHeader = args => args.Text = "Space Objects", // Adds a page header
                CustomizePageFooter = args => args.Text = "Page {0} of {1}", // Adds a page footer
            });
        }
        void OnCustomizeDocument(TreeListDocumentExportCustomizeDocumentEventArgs args) {
            // Sets default font settings for all elements in the exported document
            args.DefaultElementStyle.Font = new DXFont("Times New Roman", 12, DXFontStyle.Regular);
            // Switches the page orientation to landscape
            args.Landscape = true;
            // Sets page margins to 0.5 inches
            args.Margins = new DXMargins(50, 50, 50, 50);
            // Sets the page size to a custom value (width: 6 inches, height: 8 inches)
            args.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.Custom;
            args.PageSize = new System.Drawing.Size(600, 800);
        }
    }
    
    See Also