Back to Devexpress

GridDocumentExportOptions.CustomizeDocumentFooter Property

blazor-devexpress-dot-blazor-dot-griddocumentexportoptions-64c99116.md

latest7.9 KB
Original Source

GridDocumentExportOptions.CustomizeDocumentFooter Property

Allows you to add a document footer to the exported file.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Action<GridDocumentExportCustomizeDocumentHeaderFooterEventArgs> CustomizeDocumentFooter { get; set; }

Property Value

TypeDescription
Action<GridDocumentExportCustomizeDocumentHeaderFooterEventArgs>

A delegate method that adds a document footer.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to CustomizeDocumentFooter
GridExportEventArgs

.DocumentOptions .CustomizeDocumentFooter

|

Remarks

Call the ExportToPdf method to export Grid data to PDF. An output document contains only a table with exported data. You can add the following elements to the document:

Document HeaderLocated on the first page before the data table. Handle the CustomizeDocumentHeader event to add and style this element.Document FooterLocated on the last page after the data table. Handle the CustomizeDocumentFooter event to add and style this element.Page HeaderLocated on each page within the top margin. Handle the CustomizePageHeader event to add and style this element.Page FooterLocated on each page within the bottom margin. Handle the CustomizePageFooter event to add and style this element.

In the following image, page headers/footers are colored blue and the document header/footer is colored red:

Handle the CustomizeDocument event to configure page settings and default formatting for all elements in the exported document.

The following example exports Grid data to PDF and customizes output document appearance:

razor
@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" ExportWidth="300"/>
        <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" ExportWidth="300" />
        <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;
    DXFont defaultFont = new DXFont("Times New Roman", 12, DXFontStyle.Regular);

    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
            CustomizeDocumentHeader = OnCustomizeDocumentHeader, // Adds a document header
            CustomizeDocumentFooter = OnCustomizeDocumentFooter, // Adds a document footer
            CustomizePageHeader = OnCustomizePageHeader, // Adds page headers
            CustomizePageFooter = OnCustomizePageFooter, // Adds page footers
        });
    }
    void OnCustomizeDocument(GridDocumentExportCustomizeDocumentEventArgs args) {
        args.DefaultElementStyle.Font = defaultFont;
        args.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.B5;
    }
    void OnCustomizeDocumentHeader(GridDocumentExportCustomizeDocumentHeaderFooterEventArgs args) {
        args.ElementStyle.Font = new DXFont("Arial", 16);
        args.Text = "Weather Forecast";
    }
    void OnCustomizeDocumentFooter(GridDocumentExportCustomizeDocumentHeaderFooterEventArgs args) {
        args.ElementStyle.Font = new DXFont(defaultFont.Name, defaultFont.Size, DXFontStyle.Bold);
        args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
        args.Text = "The document data is intented for demonstration purposes only.";
    }
    void OnCustomizePageHeader(GridDocumentExportCustomizePageHeaderFooterEventArgs args) {
        args.ElementStyle.Font = new DXFont(defaultFont.Name, defaultFont.Size, DXFontStyle.Italic);
        args.Text = "Copyright © 1998-2025 Developer Express Inc.";
    }
    void OnCustomizePageFooter(GridDocumentExportCustomizePageHeaderFooterEventArgs args) {
        args.ElementStyle.Font = new DXFont(defaultFont.Name, defaultFont.Size, DXFontStyle.Italic);
        args.Text = "Page {0} of {1}";
    }
}
csharp
using System;

public class WeatherForecast {
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public string Forecast { get; set; }
    public string CloudCover { get; set; }
}
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

public class WeatherForecastService {
    private List<WeatherForecast> Forecast { get; set; }

    private static string[] CloudCover = new[] {
        "Sunny", "Partly cloudy", "Cloudy", "Storm"
    };

    Tuple<int, string>[] ConditionsForForecast = new Tuple<int, string>[] {
        Tuple.Create( 22 , "Hot"),
        Tuple.Create( 13 , "Warm"),
        Tuple.Create( 0 , "Cold"),
        Tuple.Create( -10 , "Freezing")
    };

    public WeatherForecastService() {
        Forecast = CreateForecast();
    }

    private List<WeatherForecast> CreateForecast() {
        var rng = new Random();
        DateTime startDate = DateTime.Now;
        return Enumerable.Range(1, 30).Select(index => {
            var temperatureC = rng.Next(-10, 30);
            return new WeatherForecast {
                Date = startDate.AddDays(index),
                TemperatureC = temperatureC,
                CloudCover = CloudCover[rng.Next(0, 4)],
                Forecast = ConditionsForForecast.First(c => c.Item1 <= temperatureC).Item2
            };
        }).ToList();
    }

    public List<WeatherForecast> GetForecast() {
        return Forecast;
    }

    public Task<WeatherForecast[]> GetForecastAsync(CancellationToken ct = default) {
        return Task.FromResult(Forecast.ToArray());
    }
}
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

Refer to the following topic for additional information: Export Blazor Grid Data to PDF.

See Also

GridDocumentExportOptions Class

GridDocumentExportOptions Members

DevExpress.Blazor Namespace