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

    When the PaperKind property is set to Custom, specifies a custom page size for the exported document (in hundredths of an inch).

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public Size PageSize { get; set; }

    Property Value

    Type Description
    Size

    An object that stores page width and height 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. Specify the PaperKind event argument to set the page size to a standard value (such as A4, B5, or Letter). To use a custom page size, set PaperKind to Custom, then assign a page size to the PageSize argument.

    Note

    This property is in effect only if the PaperKind property value is Custom.

    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