Skip to content

Commit 8bff13d

Browse files
committed
chore(Grid): update pdf export article and examples
1 parent 1f63941 commit 8bff13d

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

components/grid/export/pdf.md

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ position: 1
1010

1111
# PDF Export
1212

13-
You can export the grid to Pdf with a click of a button. The current filter, sort, page, grouping, column order and column size are applied to the `xlsx` document.
13+
You can export the grid to PDF with a click of a button. The current filter, sort, page, grouping, column order and column size are applied to the exported PDF document.
1414

1515
When you click the Export button, your browser will receive the resulting file.
1616

@@ -25,36 +25,42 @@ When you click the Export button, your browser will receive the resulting file.
2525

2626
## Basics
2727

28-
To enable the Grid Pdf Export, add a [command button](slug:components/grid/columns/command) with the `PdfExport` command name to the [Grid toolbar](slug:components/grid/features/toolbar).
28+
To enable the Grid PDF Export, add a [command button](slug:components/grid/columns/command) with the `PdfExport` command name to the [Grid toolbar](slug:components/grid/features/toolbar).
2929

3030
````RAZOR.skip-repl
3131
<GridToolBarTemplate>
3232
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to Pdf</GridCommandButton>
3333
</GridToolBarTemplate>
3434
````
3535

36-
Optionally, you can also set the `GridPdfExport` tag settings under the `GridExport` tag to subscribe to [Grid export events](slug:grid-export-events) that allow further customizations of the exported columns/data or configure the Pdf export options:
36+
Optionally, you can also set the `GridPdfExport` tag settings under the `GridExport` tag to subscribe to [Grid export events](slug:grid-export-events) that allow further customization of the exported columns/data or configure the PDF export options:
3737

3838
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
3939

4040
| Parameter | Type and Default&nbsp;Value | Description |
4141
| --- | --- | --- |
42-
| `FileName` | `string` | the name of the file. The grid will add the `.xslx` extension for you. |
43-
| `AllPages` | `bool` | whether to export the current page only, or the entire data from the data source. |
44-
| `PaperSize` | `GridPdfExportPaperSize` enum <br/> (`A4`) | The size of the paper for the xported file. |
42+
| `FileName` | `string` | The name of the file. The grid will add the `.pdf` extension for you. |
43+
| `AllPages` | `bool` | Whether to export the current page only, or the entire data from the data source. |
44+
| `PaperSize` | `GridPdfExportPaperSize` enum <br/> (`A4`) | The size of the paper for the exported file. |
4545
| `PageOrientation` | `GridPdfExportPageOrientation` enum <br/> (`Portrait`)| The orientation of the page - portrait and landscape. |
4646

47-
>caption Export the Grid to Pdf - Example
47+
>caption Export the Grid to PDF - Example
4848
4949
````RAZOR
5050
@* You can sort, group, filter, page the grid, resize and reodrder its columns, and you can click the
5151
Export button to save the current data *@
5252
53-
<TelerikGrid Data="@GridData" Pageable="true" Sortable="true" Resizable="true" Reorderable="true"
54-
FilterMode="@GridFilterMode.FilterRow" Groupable="true" >
53+
<TelerikGrid Data="@GridData"
54+
FilterMode="@GridFilterMode.FilterMenu"
55+
Pageable="true"
56+
Sortable="true"
57+
Reorderable="true"
58+
Resizable="true"
59+
Groupable="true"
60+
Width="650px">
5561
5662
<GridToolBarTemplate>
57-
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to Pdf</GridCommandButton>
63+
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to PDF</GridCommandButton>
5864
<label class="k-checkbox-label"><TelerikCheckBox @bind-Value="@ExportAllPages" />Export All Pages</label>
5965
</GridToolBarTemplate>
6066
@@ -64,11 +70,10 @@ Optionally, you can also set the `GridPdfExport` tag settings under the `GridExp
6470
6571
<GridColumns>
6672
<GridColumn Field="@nameof(SampleData.ProductId)" Title="ID" Width="100px" />
67-
<GridColumn Field="@nameof(SampleData.ProductName)" Title="Product Name" Width="300px" />
73+
<GridColumn Field="@nameof(SampleData.ProductName)" Title="Product Name" Width="200px" />
6874
<GridColumn Field="@nameof(SampleData.UnitsInStock)" Title="In stock" Width="100px" />
69-
<GridColumn Field="@nameof(SampleData.Price)" Title="Unit Price" Width="200px" />
70-
<GridColumn Field="@nameof(SampleData.Discontinued)" Title="Discontinued" Width="100px" />
71-
<GridColumn Field="@nameof(SampleData.FirstReleaseDate)" Title="Release Date" Width="300px" />
75+
<GridColumn Field="@nameof(SampleData.Price)" Title="Unit Price" Width="100px" />
76+
<GridColumn Field="@nameof(SampleData.Discontinued)" Title="Discontinued" Width="150px" />
7277
</GridColumns>
7378
</TelerikGrid>
7479
@@ -79,14 +84,13 @@ Optionally, you can also set the `GridPdfExport` tag settings under the `GridExp
7984
protected override void OnInitialized()
8085
{
8186
GridData = Enumerable.Range(1, 100).Select(x => new SampleData
82-
{
83-
ProductId = x,
84-
ProductName = $"Product {x}",
85-
UnitsInStock = x * 2,
86-
Price = 3.14159m * x,
87-
Discontinued = x % 4 == 0,
88-
FirstReleaseDate = DateTime.Now.AddDays(-x)
89-
}).ToList();
87+
{
88+
ProductId = x,
89+
ProductName = $"Product {x}",
90+
UnitsInStock = x * 2,
91+
Price = 3.14159m * x,
92+
Discontinued = x % 4 == 0,
93+
}).ToList();
9094
}
9195
9296
public class SampleData
@@ -96,7 +100,6 @@ Optionally, you can also set the `GridPdfExport` tag settings under the `GridExp
96100
public int UnitsInStock { get; set; }
97101
public decimal Price { get; set; }
98102
public bool Discontinued { get; set; }
99-
public DateTime FirstReleaseDate { get; set; }
100103
}
101104
}
102105
````
@@ -109,8 +112,8 @@ You can programmatically invoke the export feature of the Grid, by using the fol
109112

110113
| Method | Type | Description |
111114
| --- | --- | --- |
112-
| `SaveAsPdfFileAsync` | `ValueTask` | sends the exported Pdf file to the browser for download. |
113115
| `ExportToPdfAsync` | `Task<MemoryStream>` | returns the exported data as a `MemoryStream`. The stream itself is finalized, so that the resource does not leak. To read and work with the stream, clone its available binary data to a new `MemoryStream` instance. |
116+
| `SaveAsPdfFileAsync` | `ValueTask` | sends the exported PDF file to the browser for download. |
114117

115118
>caption Invoke the export function from code
116119
@@ -119,20 +122,21 @@ You can programmatically invoke the export feature of the Grid, by using the fol
119122
120123
@using System.IO
121124
122-
<TelerikButton OnClick="@(async () => await GridRef.SaveAsPdfFileAsync())">Download the Pdf file</TelerikButton>
125+
<TelerikButton OnClick="@(async () => await GridRef.SaveAsPdfFileAsync())">Download the PDF file</TelerikButton>
123126
<TelerikButton OnClick="@GetTheDataAsAStream">Get the Exported Data as a MemoryStream</TelerikButton>
124127
125128
<TelerikGrid @ref="@GridRef"
126129
Data="@GridData"
130+
FilterMode="@GridFilterMode.FilterMenu"
127131
Pageable="true"
128132
Sortable="true"
129-
Resizable="true"
130133
Reorderable="true"
131-
FilterMode="@GridFilterMode.FilterRow"
132-
Groupable="true">
134+
Resizable="true"
135+
Groupable="true"
136+
Width="650px">
133137
134138
<GridToolBarTemplate>
135-
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to Pdf</GridCommandButton>
139+
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to PDF</GridCommandButton>
136140
<label class="k-checkbox-label"><TelerikCheckBox @bind-Value="@ExportAllPages" />Export All Pages</label>
137141
</GridToolBarTemplate>
138142
@@ -142,11 +146,10 @@ You can programmatically invoke the export feature of the Grid, by using the fol
142146
143147
<GridColumns>
144148
<GridColumn Field="@nameof(SampleData.ProductId)" Title="ID" Width="100px" />
145-
<GridColumn Field="@nameof(SampleData.ProductName)" Title="Product Name" Width="300px" />
149+
<GridColumn Field="@nameof(SampleData.ProductName)" Title="Product Name" Width="200px" />
146150
<GridColumn Field="@nameof(SampleData.UnitsInStock)" Title="In stock" Width="100px" />
147-
<GridColumn Field="@nameof(SampleData.Price)" Title="Unit Price" Width="200px" />
148-
<GridColumn Field="@nameof(SampleData.Discontinued)" Title="Discontinued" Width="100px" />
149-
<GridColumn Field="@nameof(SampleData.FirstReleaseDate)" Title="Release Date" Width="300px" />
151+
<GridColumn Field="@nameof(SampleData.Price)" Title="Unit Price" Width="100px" />
152+
<GridColumn Field="@nameof(SampleData.Discontinued)" Title="Discontinued" Width="150px" />
150153
</GridColumns>
151154
</TelerikGrid>
152155
@@ -162,8 +165,9 @@ You can programmatically invoke the export feature of the Grid, by using the fol
162165
exportedPdfStream = new MemoryStream(finalizedStream.ToArray());
163166
}
164167
165-
List<SampleData> GridData { get; set; }
166-
bool ExportAllPages { get; set; }
168+
private List<SampleData> GridData { get; set; }
169+
170+
private bool ExportAllPages { get; set; }
167171
168172
protected override void OnInitialized()
169173
{
@@ -174,7 +178,6 @@ You can programmatically invoke the export feature of the Grid, by using the fol
174178
UnitsInStock = x * 2,
175179
Price = 3.14159m * x,
176180
Discontinued = x % 4 == 0,
177-
FirstReleaseDate = DateTime.Now.AddDays(-x)
178181
}).ToList();
179182
}
180183
@@ -185,7 +188,6 @@ You can programmatically invoke the export feature of the Grid, by using the fol
185188
public int UnitsInStock { get; set; }
186189
public decimal Price { get; set; }
187190
public bool Discontinued { get; set; }
188-
public DateTime FirstReleaseDate { get; set; }
189191
}
190192
}
191193
````
@@ -196,38 +198,35 @@ To customize the exported file, handle the `OnBeforeExport` or `OnAfterExport` e
196198

197199
The component allows you to control the data set that will be exported. It also provides built-in customization options for the columns such as `Width`, `Title` and more.
198200

199-
For more advanced customization (such as coloring the headers or bolding the titles) the Grid lets you get the `MemoryStream` of the file. Thus, you can customize it using the [`SpreadProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview) or the [`SpreadStreamProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadstreamprocessing/overview) libraries that are available with your license. Find examples on how to [format the cells of the exported Pdf file with RadSpreadProcessing](slug:grid-kb-custom-cell-formatting-with-radspreadprocessing) and how to [format the cells of the exported Pdf file with RadSpreadStreamProcessing](slug: grid-kb-custom-cell-formatting-with-radspreadstreamprocessing).
201+
For more advanced customization (such as coloring the headers or bolding the titles) the Grid lets you get the `MemoryStream` of the file. Thus, you can customize it using the [`SpreadProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview) or the [`SpreadStreamProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadstreamprocessing/overview) libraries that are available with your license. Find examples on how to [format the cells of the exported PDF file with RadSpreadProcessing](slug:grid-kb-custom-cell-formatting-with-radspreadprocessing) and how to [format the cells of the exported PDF file with RadSpreadStreamProcessing](slug: grid-kb-custom-cell-formatting-with-radspreadstreamprocessing).
200202

201203
Read more about how to [customize the exported file](slug:grid-export-events).
202204

203205
## Notes
204206

205-
The Pdf export has the following specifics:
207+
The PDF export has the following specifics:
206208

207209
* When exporting grid columns, the developer must provide column widths that are appropriate for exporting the data. While an Excel file allows resizing its columns, the PDF file format does not allow resizing the columns. The width of the column can be changed from the `OnBeforeExportEventArgs.Columns[0].Width property`, so developers have full control over this value (note that it can be different from the one defined in the corresponding grid column, thus ensuring flexibility to render the grid columns with one widths and export them in others).
208210
* We do not recommend exporting columns without widths - while Excel has a default width for a column, PDF requires fixed dimensions. We recommend setting specific widths to all columns when exporting (note that this is unrelated to the width of the column of the grid as the export width can be configured in `OnBeforeExportEventArgs.Columns[0].Width` property.
209-
* Pdf does not understand units different than `px` for the column `Width`, and if you use them (such as `rem` or `%`), it will fail to parse them and will render a collapsed (hidden) column with zero width.
211+
* PDF does not understand units different than `px` for the column `Width`, and if you use them (such as `rem` or `%`), it will fail to parse them and will render a collapsed (hidden) column with zero width.
210212
* When exporting grid columns, the developer must provide appropriate `PaperSize` and `PageOrientation` properties. For example, if you want to render 20 columns (100px each) in a A4 sheet, then this will yield unexpected results. The column dimensions in a PDF file are fixed, thus they cannot be resized as in Excel, which requires the developer to ensure proper export dimensions.
211213
* Exporting to PDF in UI for Blazor is different from exporting in Kendo jQuery, where the full HTML is exported. The Blazor export to PDF will export the Grid to a table, similar to an Excel table. If you want [to export to PDF as HTML, you can use a custom approach](#custom-export).
212-
* Templates are not exported, because there is no provision in the framework for getting them at runtime. If a column, header or group header/footer has a template or aggregates, it will be ignored. The headers will be the `Title` of the column, the data is the data from the `Field`. If you need additional information, see if you can add it in a Field in the model, or create your own Pdf file. Find a <a href="https://feedback.telerik.com/blazor/1485764-customize-the-Pdf-file-before-it-gets-to-the-client" target="_blank">project example on how to generate your own exported file</a>. Find additional information on how to [export an image that is rendered in a Grid column template](slug:grid-export-image-column-Pdf).
214+
* Templates are not exported, because there is no provision in the framework for getting them at runtime. If a column, header or group header/footer has a template or aggregates, it will be ignored. The headers will be the `Title` of the column, the data is the data from the `Field`. If you need additional information, see if you can add it in a Field in the model, or create your own PDF file. Find a <a href="https://feedback.telerik.com/blazor/1485764-customize-the-Pdf-file-before-it-gets-to-the-client" target="_blank">project example on how to generate your own exported file</a>. Find additional information on how to [export an image that is rendered in a Grid column template](slug:grid-export-image-column-Pdf).
213215

214216
@[template](/_contentTemplates/grid/export.md#export-common-notes)
215217

216218

217-
## Custom Export
219+
## Custom Export
218220

219-
The [Telerik Document Processing tools](slug:dpl-in-blazor) that come with your Blazor license let you generate a PDF file based on the data in the grid.
221+
If you want to have full control over the PDF export, you can perform it with a custom approach.
220222

221223
The following sample projects show two ways to implement a PDF export
222224

223-
* <a href="https://github.com/telerik/blazor-ui/tree/master/grid/pdf-export-server" target="_blank">Export Grid to PDF on the Server</a> - gets the `DataSourceRequest` from the grid and sends it to the server service for processing. It is used to let you fetch the same data that the grid has (including paging, filtering, sorting) so you can generate the PDF. For WebAssembly apps, this improves the performance by not generating the file in the browser, which is, at the time of writing, too slow for a real-life scenario.
224-
225-
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/pdf-jpg-export-js" target="_blank">PDF and JPG Export in the Browser with JS</a> - uses Kendo JS libraries to generate the PDF file from the current DOM in the browser.
226-
225+
* <a href="https://github.com/telerik/blazor-ui/tree/master/grid/pdf-export-server" target="_blank">Export Grid to PDF on the Server</a> - This export is achieved through the [Telerik Document Processing tools](slug:dpl-in-blazor) that come with your Blazor license. The example shows how to get the `DataSourceRequest` from the Grid and send it to the server service for processing. Thus, you can fetch the same data that the Grid has (including paging, filtering, sorting) so you can generate the PDF. For WebAssembly apps, this improves the performance by not generating the file in the browser, which is, at the time of writing, too slow for a real-life scenario.
227226

228-
You can also follow the feature request for <a href="https://feedback.telerik.com/blazor/1434269-export-grid-to-pdf" target="_blank">built-in Grid export to PDF</a>.
227+
* <a href="https://github.com/telerik/blazor-ui/tree/master/common/pdf-jpg-export-js" target="_blank">PDF and JPG Export in the Browser with JS</a> - This sample uses Kendo JS libraries to generate the PDF file from the current DOM in the browser.
229228

230229
## See Also
231230

232231
* [Blazor Grid](slug:grid-overview)
233-
* [Live Demo: Grid Pdf Export](https://demos.telerik.com/blazor-ui/grid/export-Pdf)
232+
* [Live Demo: Grid PDF Export](https://demos.telerik.com/blazor-ui/grid/export-Pdf)

0 commit comments

Comments
 (0)