Skip to content

Commit 1f2219c

Browse files
authored
Show how to set PDF export options (#315)
1 parent dad0564 commit 1f2219c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

common/pdf-jpg-export-js/PdfExportJS/Components/Pages/Home.razor

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
<div @ref="@ElementToExport">
1111
<TelerikGrid Data="@GridData"
12-
Pageable="true"
13-
Sortable="true"
14-
FilterMode="@GridFilterMode.FilterRow"
12+
FilterMode="@GridFilterMode.FilterMenu"
1513
Groupable="true"
14+
Pageable="true"
1615
Resizable="true"
17-
Reorderable="true">
16+
Reorderable="true"
17+
Sortable="true">
1818
<GridToolBarTemplate>
1919
<TelerikButton OnClick="@ExportJpg"
2020
ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
@@ -27,7 +27,7 @@
2727
<GridColumn Field="@(nameof(SampleData.Id))" Width="120px" />
2828
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Groupable="false" />
2929
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
30-
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
30+
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" DisplayFormat="{0:d}" />
3131
</GridColumns>
3232
</TelerikGrid>
3333
</div>
@@ -45,8 +45,10 @@
4545

4646
private async Task ExportPdf()
4747
{
48+
// Define PDF export options
49+
object pdfOptions = new { Landscape = true, PaperSize = "A4" };
4850
// Create a data URI from the element reference
49-
var data = await DrawingService.ExportPDF(ElementToExport);
51+
string data = await DrawingService.ExportPDF(ElementToExport, pdfOptions);
5052
// Save the Data URI to a file
5153
await DrawingService.SaveAs(data, "grid-pdf-export.pdf");
5254
}

common/pdf-jpg-export-js/PdfExportJS/Services/DrawingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public async ValueTask<string> ExportImage(ElementReference elementRef) =>
2727
/// </summary>
2828
/// <param name="elementRef"></param>
2929
/// <returns>Data URI as a string</returns>
30-
public async ValueTask<string> ExportPDF(ElementReference elementRef) =>
31-
await Js.InvokeAsync<string>($"{JsNamespace}.exportPDF", elementRef);
30+
public async ValueTask<string> ExportPDF(ElementReference elementRef, object? options) =>
31+
await Js.InvokeAsync<string>($"{JsNamespace}.exportPDF", elementRef, options);
3232

3333
/// <summary>
3434
/// Invokes the browser to save a Data URI formatted string to a file.

0 commit comments

Comments
 (0)