GridDocumentExportOptionsBase.FitToPage Property
Specifies whether the exported table width fits the page width.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(true)]
public bool FitToPage { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Boolean | true |
|
Remarks
A column’s ExportWidth
property specifies the column width (in pixels) when data is exported to XLS, XLSX, or PDF. The default column width is 200px
. Handle the CustomizeColumn
event and specify the Width event argument to modify the column width only when data is exported to PDF.
During PDF export operations, Grid and TreeList components recalculate column widths so that the output table occupies all available space (the page width minus left and right margins). For instance:
- If the total column width is 3 times more than the available page width, the column width is
column.ExportWidth / 3
. - If the total column width is 3 times less than the available page width, the column width is
column.ExportWidth * 3
.
Set the FitToPage
property to false
to use the exact ExportWidth
/Width
property values for exported document columns. If a page does not have enough space to render a column, then this and subsequent columns are moved to the next page (similar to the Summary column in the image below).
Grid Example
The following example exports Grid data to PDF. Columns in the exported document have the following widths:
- Date - 200 pixels (default)
- Temperature (C) and Temperature (F) - 350 pixels
- Summary - 450 pixels
@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="350" />
<DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" ExportWidth="350" />
<DxGridDataColumn Caption="Summary" FieldName="Summary" ExportWidth="450" />
</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() {
FitToPage = false,
CustomizeDocument = args => {
args.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A6;
args.Margins = new DXMargins(50, 50, 50, 50);
},
});
}
}
TreeList Example
The following example exports Grid data to PDF. Columns in the exported document have the following widths:
- Name - 300 pixels
- Type - 200 pixels (default)
- Mass, kg and Radius, km - 350 pixels
@rendermode InteractiveServer
@using DevExpress.Drawing
@inject SpaceObjectDataProvider SpaceObjectDataProvider
<DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites">
<Columns>
<DxTreeListDataColumn FieldName="Name" ExportWidth="300" />
<DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
<DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" ExportWidth="350" DisplayFormat="N2" />
<DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" ExportWidth="350" 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() {
FitToPage = false,
CustomizeDocument = args => {
args.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A6;
args.Margins = new DXMargins(50, 50, 50, 50);
},
});
}
}