From 8672073b6b1c23f2f47ce941a9eaafd29776103f Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:58:38 +0300 Subject: [PATCH 01/31] docs(pdfviewer): Add Overview and Events page --- _config.yml | 2 + components/pdfviewer/events.md | 84 +++++++++++++++++++++++++++ components/pdfviewer/overview.md | 98 ++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 components/pdfviewer/events.md create mode 100644 components/pdfviewer/overview.md diff --git a/_config.yml b/_config.yml index e910716079..ea478be8ce 100644 --- a/_config.yml +++ b/_config.yml @@ -374,6 +374,8 @@ navigation: title: "Popup" "*numerictextbox": title: "NumericTextBox" + "*pdfviewer": + title: "PDF Viewer" "*progressbar": title: "ProgressBar" "*qrcode": diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md new file mode 100644 index 0000000000..b49a1a98ac --- /dev/null +++ b/components/pdfviewer/events.md @@ -0,0 +1,84 @@ +--- +title: Events +page_title: Events | PdfViewer for Blazor +description: Events of the PDF Viewer for Blazor. +slug: pdfviewer-events +tags: telerik,blazor,pdf,pdfviewer +published: True +position: 5 +--- + +# PdfViewer Events + +This article describes the Blazor PDF Viewer events. + +* [`OnDownload`](#ondownload) +* [`OnOpen`](#onopen) + + +## OnDownload + +The `OnDownload` event fires when the user clicks on the Download button in the PDF Viewer toolbar. + +The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. See [example below](#example). + + +## OnOpen + +The `OnOpen` event fires when the user selects a file to open, after clicking on the Open button in the PDF Viewer toolbar. + +The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. See [example below](#example). + + +## Example + +>caption Handle Blazor PDF Viewer Events + +````CSHTML +

Opened file @PdfName with size @PdfSize.ToString() bytes.

+ + + + +@code { + private TelerikPdfViewer PdfViewerRef { get; set; } + + private byte[] PdfSource { get; set; } + + private string PdfName { get; set; } = "..."; + + private long PdfSize { get; set; } + + private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) + { + //args.IsCancelled = true; + + args.FileName = "PDF-Viewer-" + DateTime.Now.Millisecond; + } + + private async Task OnPdfOpen(PdfViewerOpenEventArgs args) + { + //args.IsCancelled = true; + + var file = args.Files.FirstOrDefault(); + + PdfName = file.Name; + PdfSize = file.Size; + + var buffer = new byte[file.Stream.Length]; + await file.Stream.ReadAsync(buffer); + + PdfSource = buffer; + PdfViewerRef.LoadFile(PdfSource); + } +} +```` + + +## See Also + +* [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) +* [PdfViewer API](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md new file mode 100644 index 0000000000..f631e2594b --- /dev/null +++ b/components/pdfviewer/overview.md @@ -0,0 +1,98 @@ +--- +title: Overview +page_title: Overview | PdfViewer for Blazor +description: Overview of the PDF Viewer for Blazor. +slug: pdfviewer-overview +tags: telerik,blazor,pdf,pdfviewer +published: True +position: 0 +--- + +# Blazor PdfViewer Overview + +The Pdf Viewer for Blazor allows users to open PDF files directly in the browser. The component provides all major features, such as paging, zooming and printing. In addition, users can upload and display a PDF file from their local device, or download the currently open file. + + +## Creating Blazor PdfViewer + +To use a Telerik PDF Viewer for Blazor: + +1. Add the `TelerikPdfViewer` tag. +1. Set its `FileData` parameter to a byte array that will hold the PDF file contents. +1. Define the component reference via the `@ref` directive. You will need it to call the `LoadFile` method to actually display the PDF file in the component. +1. (optional) Subscribe to the PDF Viewer's `OnOpen` event, if users will be opening files from their local devices. The event argument is a `PdfViewerOpenEventArgs` object with a `Files` property. Use `Files` in the same way as with the [`OnSelect` event of the FileSelect component]({%slug fileselect-events%}#onselect). +1. (optional) Set `Width` and `Height` in any [supported CSS unit]({%slug common-features/dimensions%}). + +>caption Basic Blazor PDF Viewer + +````CSHTML + + + +@code { + private TelerikPdfViewer PdfViewerRef { get; set; } + + private byte[] PdfSource { get; set; } + + private async Task OnPdfOpen(PdfViewerOpenEventArgs args) + { + var file = args.Files.FirstOrDefault(); + var buffer = new byte[file.Stream.Length]; + await file.Stream.ReadAsync(buffer); + + PdfSource = buffer; + PdfViewerRef.LoadFile(PdfSource); + } + + // automatically display the sample PDF + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await Task.Delay(100); + PdfSource = Convert.FromBase64String(SamplePdf); + PdfViewerRef.LoadFile(PdfSource); + } + + await base.OnAfterRenderAsync(firstRender); + } + + private string SamplePdf { get; set; } = @"JVBERi0xLjENCiXCpcKxw6sNCg0KMSAwIG9iag0KICA8PCAvVHlwZSAvQ2F0YWxvZw0KICAgICAvUGFnZXMgMiAwIFINCiAgPj4NCmVuZG9iag0KDQoyIDAgb2JqDQogIDw8IC9UeXBlIC9QYWdlcw0KICAgICAvS2lkcyBbMyAwIFJdDQogICAgIC9Db3VudCAxDQogICAgIC9NZWRpYUJveCBbMCAwIDMwMCAxNDRdDQogID4+DQplbmRvYmoNCg0KMyAwIG9iag0KICA8PCAgL1R5cGUgL1BhZ2UNCiAgICAgIC9QYXJlbnQgMiAwIFINCiAgICAgIC9SZXNvdXJjZXMNCiAgICAgICA8PCAvRm9udA0KICAgICAgICAgICA8PCAvRjENCiAgICAgICAgICAgICAgIDw8IC9UeXBlIC9Gb250DQogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTENCiAgICAgICAgICAgICAgICAgIC9CYXNlRm9udCAvVGltZXMtUm9tYW4NCiAgICAgICAgICAgICAgID4+DQogICAgICAgICAgID4+DQogICAgICAgPj4NCiAgICAgIC9Db250ZW50cyA0IDAgUg0KICA+Pg0KZW5kb2JqDQoNCjQgMCBvYmoNCiAgPDwgL0xlbmd0aCA1OSA+Pg0Kc3RyZWFtDQogIEJUDQogICAgL0YxIDE4IFRmDQogICAgMCAwIFRkDQogICAgKFRlbGVyaWsgUGRmVmlld2VyIGZvciBCbGF6b3IpIFRqDQogIEVUDQplbmRzdHJlYW0NCmVuZG9iag0KDQp4cmVmDQowIDUNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAyMSAwMDAwMCBuDQowMDAwMDAwMDg2IDAwMDAwIG4NCjAwMDAwMDAxOTUgMDAwMDAgbg0KMDAwMDAwMDQ5MCAwMDAwMCBuDQp0cmFpbGVyDQogIDw8ICAvUm9vdCAxIDAgUg0KICAgICAgL1NpemUgNQ0KICA+Pg0Kc3RhcnR4cmVmDQo2MDkNCiUlRU9GDQo="; +} +```` + +## PdfViewer Parameters + +The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API Reference](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) for all parameters, methods and events. + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Parameter | Type and Default Value | Description | +| --- | --- | --- | +| `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | +| `FileData` | `byte[]` | The source of the currently displayed PDF file. | +| `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, according to its content. | +| `Page` | `int`
(`1`) | The current page of the visible PDF document. | +| `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | + + +## PdfViewer Reference and Methods + +The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute (see the [basic example above](#creating-blazor-pdfviewer)). The PdfViewer methods are: + +* `LoadFile` - renders the document that is passed as a `byte[]` argument. +* `Refresh` - ??? + + +## Next Steps + +* [Handle PDF Viewer events]({%slug pdfviewer-events%}) + + +## See Also + +* [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) +* [PdfViewer API](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) From 3d7e4b47d40f46c68f4da572e5c8bf750492821e Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:15:10 +0300 Subject: [PATCH 02/31] docs(pdfviewer): Add Toolbar page --- components/pdfviewer/events.md | 8 +++++++- components/pdfviewer/overview.md | 13 +++++++++++++ components/pdfviewer/toolbar.md | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 components/pdfviewer/toolbar.md diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index b49a1a98ac..d08cac4015 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -5,7 +5,7 @@ description: Events of the PDF Viewer for Blazor. slug: pdfviewer-events tags: telerik,blazor,pdf,pdfviewer published: True -position: 5 +position: 50 --- # PdfViewer Events @@ -78,6 +78,12 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo ```` +## Next Steps + +* [Customize the PDF Viewer toolbar]({%slug pdfviewer-toolbar%}) +* [Handle PDF Viewer events]({%slug pdfviewer-events%}) + + ## See Also * [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index f631e2594b..5c6c4fbab4 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -64,6 +64,18 @@ To use a Telerik PDF Viewer for Blazor: } ```` + +## Toolbar + +The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). By default, it displays the following tools: + +* a pager +* zoom buttons and a dropdown +* search button +* open and download buttons +* print button + + ## PdfViewer Parameters The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API Reference](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) for all parameters, methods and events. @@ -89,6 +101,7 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a ## Next Steps +* [Customize the PDF Viewer toolbar]({%slug pdfviewer-toolbar%}) * [Handle PDF Viewer events]({%slug pdfviewer-events%}) diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md new file mode 100644 index 0000000000..a9c7fd0c09 --- /dev/null +++ b/components/pdfviewer/toolbar.md @@ -0,0 +1,32 @@ +--- +title: Toolbar +page_title: Toolbar | PdfViewer for Blazor +description: Toolbar of the PDF Viewer for Blazor. +slug: pdfviewer-toolbar +tags: telerik,blazor,pdf,pdfviewer +published: True +position: 5 +--- + +# PdfViewer Toolbar + +The PDF Viewer toolbar can render built-in and custom tools. By default, it displays the following tools: + +* a pager +* zoom buttons and a dropdown +* search button +* open and download buttons +* print button + + +>caption Customize the Blazor PDF Viewer Toolbar + +````CSHTML + +```` + + +## See Also + +* [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) +* [PdfViewer API](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) From 0995ea320921b684fc43a1414b6522e234ab2003 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Thu, 25 Aug 2022 11:07:41 +0300 Subject: [PATCH 03/31] chore(pdfviewer): Rename API members --- components/pdfviewer/events.md | 3 +-- components/pdfviewer/overview.md | 11 ++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index d08cac4015..bed15ac760 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -38,7 +38,7 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo

Opened file @PdfName with size @PdfSize.ToString() bytes.

@@ -72,7 +72,6 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo await file.Stream.ReadAsync(buffer); PdfSource = buffer; - PdfViewerRef.LoadFile(PdfSource); } } ```` diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 5c6c4fbab4..cb78b86b60 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -18,7 +18,7 @@ The Pdf To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. -1. Set its `FileData` parameter to a byte array that will hold the PDF file contents. +1. Set its `Data` parameter to a byte array that will hold the PDF file contents. 1. Define the component reference via the `@ref` directive. You will need it to call the `LoadFile` method to actually display the PDF file in the component. 1. (optional) Subscribe to the PDF Viewer's `OnOpen` event, if users will be opening files from their local devices. The event argument is a `PdfViewerOpenEventArgs` object with a `Files` property. Use `Files` in the same way as with the [`OnSelect` event of the FileSelect component]({%slug fileselect-events%}#onselect). 1. (optional) Set `Width` and `Height` in any [supported CSS unit]({%slug common-features/dimensions%}). @@ -27,7 +27,7 @@ To use a Telerik PDF Viewer for Blazor: ````CSHTML @@ -44,7 +44,6 @@ To use a Telerik PDF Viewer for Blazor: await file.Stream.ReadAsync(buffer); PdfSource = buffer; - PdfViewerRef.LoadFile(PdfSource); } // automatically display the sample PDF @@ -54,7 +53,6 @@ To use a Telerik PDF Viewer for Blazor: { await Task.Delay(100); PdfSource = Convert.FromBase64String(SamplePdf); - PdfViewerRef.LoadFile(PdfSource); } await base.OnAfterRenderAsync(firstRender); @@ -85,7 +83,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | Parameter | Type and Default Value | Description | | --- | --- | --- | | `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | -| `FileData` | `byte[]` | The source of the currently displayed PDF file. | +| `Data` | `byte[]` | The source of the currently displayed PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, according to its content. | | `Page` | `int`
(`1`) | The current page of the visible PDF document. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | @@ -95,8 +93,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute (see the [basic example above](#creating-blazor-pdfviewer)). The PdfViewer methods are: -* `LoadFile` - renders the document that is passed as a `byte[]` argument. -* `Refresh` - ??? +* `Rebind` - ??? ## Next Steps From 52466a750bcde537a07b114faf15f4fe6365b4e4 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Thu, 25 Aug 2022 18:02:33 +0300 Subject: [PATCH 04/31] docs(pdfviewer): Update, according to latest dev state --- components/pdfviewer/events.md | 52 +++++++++++++--------- components/pdfviewer/overview.md | 76 ++++++++++++++++++-------------- components/pdfviewer/toolbar.md | 46 ++++++++++++++++--- 3 files changed, 112 insertions(+), 62 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index bed15ac760..ecc365b9f6 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -18,16 +18,16 @@ This article describes the Blazor PDF Viewer events. ## OnDownload -The `OnDownload` event fires when the user clicks on the Download button in the PDF Viewer toolbar. +The `OnDownload` event fires when the user clicks on the Download button in the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). -The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. See [example below](#example). +The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. See the [example below](#example). ## OnOpen -The `OnOpen` event fires when the user selects a file to open, after clicking on the Open button in the PDF Viewer toolbar. +The `OnOpen` event fires when the user selects a file to open from the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). -The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. See [example below](#example). +The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. See the [example below](#example). ## Example @@ -35,43 +35,52 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo >caption Handle Blazor PDF Viewer Events ````CSHTML -

Opened file @PdfName with size @PdfSize.ToString() bytes.

+

Last opened file by the user: @PdfName, with size @PdfSize.ToString() bytes.

- Last event: @EventLog

+ + + OnOpen="@OnPdfOpen" + Height="600px"> @code { - private TelerikPdfViewer PdfViewerRef { get; set; } - private byte[] PdfSource { get; set; } private string PdfName { get; set; } = "..."; private long PdfSize { get; set; } + private string EventLog { get; set; } = "..."; + private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) { //args.IsCancelled = true; - - args.FileName = "PDF-Viewer-" + DateTime.Now.Millisecond; + args.FileName = "PDF-Viewer-Download"; + EventLog = "Download successful."; } private async Task OnPdfOpen(PdfViewerOpenEventArgs args) { - //args.IsCancelled = true; - var file = args.Files.FirstOrDefault(); - PdfName = file.Name; - PdfSize = file.Size; - - var buffer = new byte[file.Stream.Length]; - await file.Stream.ReadAsync(buffer); - - PdfSource = buffer; + if (file.Size > 1_000_000) + { + args.IsCancelled = true; + EventLog = "Open rejected. File too large."; + } + else + { + PdfName = file.Name; + PdfSize = file.Size; + + var buffer = new byte[file.Stream.Length]; + await file.Stream.ReadAsync(buffer); + PdfSource = buffer; + + EventLog = "Open successful."; + } } } ```` @@ -80,7 +89,6 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo ## Next Steps * [Customize the PDF Viewer toolbar]({%slug pdfviewer-toolbar%}) -* [Handle PDF Viewer events]({%slug pdfviewer-events%}) ## See Also diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index cb78b86b60..ea7c7cee45 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -18,44 +18,31 @@ The
Pdf To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. -1. Set its `Data` parameter to a byte array that will hold the PDF file contents. -1. Define the component reference via the `@ref` directive. You will need it to call the `LoadFile` method to actually display the PDF file in the component. -1. (optional) Subscribe to the PDF Viewer's `OnOpen` event, if users will be opening files from their local devices. The event argument is a `PdfViewerOpenEventArgs` object with a `Files` property. Use `Files` in the same way as with the [`OnSelect` event of the FileSelect component]({%slug fileselect-events%}#onselect). -1. (optional) Set `Width` and `Height` in any [supported CSS unit]({%slug common-features/dimensions%}). +1. Set the `Data` parameter to a byte array that will hold the PDF file contents. +1. (optional) Subscribe to the PDF Viewer's [`OnDownload`]({%slug pdfviewer-events%}#ondownload) or [`OnOpen`]({%slug pdfviewer-events%}#onopen) events, if users will be downloading or opening local files. +1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. >caption Basic Blazor PDF Viewer ````CSHTML - @code { - private TelerikPdfViewer PdfViewerRef { get; set; } - private byte[] PdfSource { get; set; } - private async Task OnPdfOpen(PdfViewerOpenEventArgs args) + private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) { - var file = args.Files.FirstOrDefault(); - var buffer = new byte[file.Stream.Length]; - await file.Stream.ReadAsync(buffer); - - PdfSource = buffer; + args.FileName = "PDF-Viewer-Download"; } - // automatically display the sample PDF - protected override async Task OnAfterRenderAsync(bool firstRender) + protected override void OnInitialized() { - if (firstRender) - { - await Task.Delay(100); - PdfSource = Convert.FromBase64String(SamplePdf); - } + PdfSource = Convert.FromBase64String(SamplePdf); - await base.OnAfterRenderAsync(firstRender); + base.OnInitialized(); } private string SamplePdf { get; set; } = @"JVBERi0xLjENCiXCpcKxw6sNCg0KMSAwIG9iag0KICA8PCAvVHlwZSAvQ2F0YWxvZw0KICAgICAvUGFnZXMgMiAwIFINCiAgPj4NCmVuZG9iag0KDQoyIDAgb2JqDQogIDw8IC9UeXBlIC9QYWdlcw0KICAgICAvS2lkcyBbMyAwIFJdDQogICAgIC9Db3VudCAxDQogICAgIC9NZWRpYUJveCBbMCAwIDMwMCAxNDRdDQogID4+DQplbmRvYmoNCg0KMyAwIG9iag0KICA8PCAgL1R5cGUgL1BhZ2UNCiAgICAgIC9QYXJlbnQgMiAwIFINCiAgICAgIC9SZXNvdXJjZXMNCiAgICAgICA8PCAvRm9udA0KICAgICAgICAgICA8PCAvRjENCiAgICAgICAgICAgICAgIDw8IC9UeXBlIC9Gb250DQogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTENCiAgICAgICAgICAgICAgICAgIC9CYXNlRm9udCAvVGltZXMtUm9tYW4NCiAgICAgICAgICAgICAgID4+DQogICAgICAgICAgID4+DQogICAgICAgPj4NCiAgICAgIC9Db250ZW50cyA0IDAgUg0KICA+Pg0KZW5kb2JqDQoNCjQgMCBvYmoNCiAgPDwgL0xlbmd0aCA1OSA+Pg0Kc3RyZWFtDQogIEJUDQogICAgL0YxIDE4IFRmDQogICAgMCAwIFRkDQogICAgKFRlbGVyaWsgUGRmVmlld2VyIGZvciBCbGF6b3IpIFRqDQogIEVUDQplbmRzdHJlYW0NCmVuZG9iag0KDQp4cmVmDQowIDUNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAyMSAwMDAwMCBuDQowMDAwMDAwMDg2IDAwMDAwIG4NCjAwMDAwMDAxOTUgMDAwMDAgbg0KMDAwMDAwMDQ5MCAwMDAwMCBuDQp0cmFpbGVyDQogIDw8ICAvUm9vdCAxIDAgUg0KICAgICAgL1NpemUgNQ0KICA+Pg0Kc3RhcnR4cmVmDQo2MDkNCiUlRU9GDQo="; @@ -65,13 +52,15 @@ To use a Telerik PDF Viewer for Blazor: ## Toolbar -The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). By default, it displays the following tools: +The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools are related to the built-in features such as: -* a pager -* zoom buttons and a dropdown -* search button -* open and download buttons -* print button +* Paging +* Zoom +* Text selection +* Pan +* Search +* Open and download +* Print ## PdfViewer Parameters @@ -82,18 +71,39 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | Parameter | Type and Default Value | Description | | --- | --- | --- | -| `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | +| `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | | `Data` | `byte[]` | The source of the currently displayed PDF file. | -| `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, according to its content. | +| `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | | `Page` | `int`
(`1`) | The current page of the visible PDF document. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | ## PdfViewer Reference and Methods -The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute (see the [basic example above](#creating-blazor-pdfviewer)). The PdfViewer methods are: +The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute. The PdfViewer methods are: + +* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the current file `Data`. + +>caption PDF Viewer reference and method usage + +````CSHTML +Rebind PDF Viewer + + + + +@code { + private TelerikPdfViewer PdfViewerRef { get; set; } + + private byte[] PdfSource { get; set; } -* `Rebind` - ??? + private async Task OnButtonClick() + { + PdfViewerRef.Rebind(); + } +} +```` ## Next Steps diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index a9c7fd0c09..3d619baee9 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -10,22 +10,54 @@ position: 5 # PdfViewer Toolbar -The PDF Viewer toolbar can render built-in and custom tools. By default, it displays the following tools: +The PDF Viewer toolbar can render built-in and custom tools. This article describes the built-in tools and shows how to customize the toolbar. -* a pager -* zoom buttons and a dropdown -* search button -* open and download buttons -* print button +## Built-in Tools ->caption Customize the Blazor PDF Viewer Toolbar +By default, the PDF Viewer displays the following tools: + +* Pager to navigate the PDF document via automatic scrolling. Paging requires the `Height` parameter to be set, otherwise the component expands and doesn't have its own scrollbar. +* Zoom in and zoom out buttons; +* Zooming dropdown with common options (Fit to page, Fit to width, 100%, etc.); +* Text selection button +* Pan button +* Search button that opens an additional search bar. It contains a textbox and arrow buttons to navigate the search results. +* Open button. Requires the [`OnOpen` handler]({%slug pdfviewer-events%}#onopen) to be implemented. +* Download button. Requires the [`OnDownload` handler]({%slug pdfviewer-events%}#ondownload) to be implemented. +* Print button; + +>caption Customize the built-in PDF Viewer tools + +````CSHTML + + + +@code { + private byte[] PdfSource { get; set; } +} +```` + + +## Custom Tools + +>caption Configure a custom PDF Viewer tool ````CSHTML + + +@code { + private byte[] PdfSource { get; set; } +} ```` +## Next Steps + +* [Handle PDF Viewer events]({%slug pdfviewer-events%}) + + ## See Also * [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) From 5380922811af7a5f73e334f894c2e76146cecb4e Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:17:47 +0300 Subject: [PATCH 05/31] docs(pdfviewer): OnError event, Tool table and random polishing --- components/pdfviewer/events.md | 26 ++++++++-- components/pdfviewer/overview.md | 13 ++++- components/pdfviewer/toolbar.md | 83 +++++++++++++++++++++++--------- 3 files changed, 91 insertions(+), 31 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index ecc365b9f6..7da3a81396 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -1,18 +1,19 @@ --- title: Events -page_title: Events | PdfViewer for Blazor +page_title: PdfViewer - Events description: Events of the PDF Viewer for Blazor. slug: pdfviewer-events tags: telerik,blazor,pdf,pdfviewer published: True -position: 50 +position: 20 --- # PdfViewer Events -This article describes the Blazor PDF Viewer events. +This article describes the Blazor PDF Viewer events and provides a runnable example with sample event handler implementations. * [`OnDownload`](#ondownload) +* [`OnError`](#onerror) * [`OnOpen`](#onopen) @@ -23,6 +24,13 @@ The `OnDownload` event fires when the user clicks on the Download button in the The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. See the [example below](#example). +## OnError + +The `OnError` event fires when a file error occurs. For example, the user tries to open a corrupt file or a file that is not in the correct format. + +The event handler receives an argument of type [`PdfViewerErrorEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerErrorEventArgs), which exposes a `Message` property. See the [example below](#example). + + ## OnOpen The `OnOpen` event fires when the user selects a file to open from the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). @@ -32,7 +40,7 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo ## Example ->caption Handle Blazor PDF Viewer Events +>caption Handle or cancel Blazor PDF Viewer Events ````CSHTML

Last opened file by the user: @PdfName, with size @PdfSize.ToString() bytes.

@@ -41,6 +49,7 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo @@ -61,6 +70,12 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo EventLog = "Download successful."; } + private async Task OnPdfError(PdfViewerErrorEventArgs args) + { + // Rename a random non-PDF file to error.pdf and try to open it. + EventLog = "Open failed. The Error message was: " + args.Message; + } + private async Task OnPdfOpen(PdfViewerOpenEventArgs args) { var file = args.Files.FirstOrDefault(); @@ -75,9 +90,10 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo PdfName = file.Name; PdfSize = file.Size; + // Get the PDF file contents if necessary. + // It is not necessary to set the Data parameter value here. var buffer = new byte[file.Stream.Length]; await file.Stream.ReadAsync(buffer); - PdfSource = buffer; EventLog = "Open successful."; } diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index ea7c7cee45..4f024b8480 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -1,6 +1,6 @@ --- title: Overview -page_title: Overview | PdfViewer for Blazor +page_title: PdfViewer - Overview description: Overview of the PDF Viewer for Blazor. slug: pdfviewer-overview tags: telerik,blazor,pdf,pdfviewer @@ -63,6 +63,11 @@ The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-to * Print +## Large File Support + +The PDF Viewer uses a [FileSelect component]({%slug fileselect-overview%}) to open files from the user device. In Blazor **Server** apps, the FileSelect uses the **SignalR WebSocket**, which has a default maximum message size of **32 KB**. To work with larger files, [increase the max WebSocket message size for the Blazor application]({%slug fileselect-overview%}#large-file-support). + + ## PdfViewer Parameters The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API Reference](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) for all parameters, methods and events. @@ -73,9 +78,13 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | --- | --- | --- | | `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | | `Data` | `byte[]` | The source of the currently displayed PDF file. | +| `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation for operations that take more than 600 ms. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | -| `Page` | `int`
(`1`) | The current page of the visible PDF document. | +| `MaxZoom` | `double`
(`4`) | The largest possible zoom in. The default value is 400%. | +| `MinZoom` | `double`
(`0.5`) | The largest possible zoom out. The default value is 50%. | +| `Page` | `int`
(`1`) | The current page of the loaded PDF document. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | +| `ZoomRate` | `double`
(`0.25`) | The zoom level change that is used by the zoom in and zoom out buttons. | ## PdfViewer Reference and Methods diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index 3d619baee9..7ff3bbbf50 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -1,54 +1,89 @@ --- title: Toolbar -page_title: Toolbar | PdfViewer for Blazor +page_title: PdfViewer - Toolbar description: Toolbar of the PDF Viewer for Blazor. slug: pdfviewer-toolbar tags: telerik,blazor,pdf,pdfviewer published: True -position: 5 +position: 10 --- # PdfViewer Toolbar -The PDF Viewer toolbar can render built-in and custom tools. This article describes the built-in tools and shows how to customize the toolbar. +The PDF Viewer toolbar can render built-in and custom tools. This article describes the built-in tools and shows how to add custom tools or customize the toolbar. ## Built-in Tools -By default, the PDF Viewer displays the following tools: +By default, the PDF Viewer displays all its built-in tools in the listed order below. Use the *tool tag* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-customization). -* Pager to navigate the PDF document via automatic scrolling. Paging requires the `Height` parameter to be set, otherwise the component expands and doesn't have its own scrollbar. -* Zoom in and zoom out buttons; -* Zooming dropdown with common options (Fit to page, Fit to width, 100%, etc.); -* Text selection button -* Pan button -* Search button that opens an additional search bar. It contains a textbox and arrow buttons to navigate the search results. -* Open button. Requires the [`OnOpen` handler]({%slug pdfviewer-events%}#onopen) to be implemented. -* Download button. Requires the [`OnDownload` handler]({%slug pdfviewer-events%}#ondownload) to be implemented. -* Print button; +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) ->caption Customize the built-in PDF Viewer tools +| Tool Name | Tool Tag | Description | +| --- | --- | --- | +| Pager | `PdfViewerToolBarPagerTool` | A pager to navigate the PDF document via automatic scrolling. Paging requires the [`Height` parameter]({%slug pdfviewer-overview%}#pdfviewer-parameters) to be set, otherwise the component expands and doesn't have its own scrollbar. | +| Zoom | `PdfViewerToolBarZoomTool` | Zoom in and zoom out buttons with an additional dropdown with common options (Fit to page, Fit to width, 100%, etc.) | +| Selection | `PdfViewerToolBarSelectionTool` | Two toggle buttons that enable either text selection or panning. | +| Search | `PdfViewerToolBarSearchTool` | A search button. It opens an additional search bar that contains a textbox and arrow buttons to navigate the search results. | +| Open | `PdfViewerToolBarOpenTool` | An open button. It fires the [`OnOpen` event]({%slug pdfviewer-events%}#onopen). | +| Download | `PdfViewerToolBarDownloadTool` | A download button. It fires the [`OnDownload` event]({%slug pdfviewer-events%}#ondownload). | +| Print | `PdfViewerToolBarPrintTool` | A print button. | -````CSHTML - - - -@code { - private byte[] PdfSource { get; set; } -} -```` +The default toolbar user interface also includes separators (``) and spacers (``). The separators render as a vertical line. Spacers consume the available empty space and push the rest of the tools next to one another. ## Custom Tools ->caption Configure a custom PDF Viewer tool +In addition to built-in tools, the PDF Viewer also supports custom tools. Use the `` tag, which is a standard Blazor `RenderFragment`. Render the desired custom tool UI as `ChildContent` inside the tag. + + +## Toolbar Customization + +Add a `` tag inside the `` tag to: + +* Arrange the PDF Viewer tools in a specific order; +* Remove some of the built-in tools; +* Add custom tools. + +>caption Customize the PDF Viewer toolbar ````CSHTML - + + + + Custom PDF Tool + + + + + + + + + + + + + + + + + @code { private byte[] PdfSource { get; set; } + + private async Task OnPdfCustomClick() + { + // ... + } + + private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) + { + args.FileName = "PDF-Viewer-Download"; + } } ```` From 2b37412f79dbe5f59bfcf4ba925fa1b9587cd5a3 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:30:31 +0300 Subject: [PATCH 06/31] docs(pdfviewer): Random polishing --- components/pdfviewer/events.md | 2 +- components/pdfviewer/overview.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index 7da3a81396..5a53d31751 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -21,7 +21,7 @@ This article describes the Blazor PDF Viewer events and provides a runnable exam The `OnDownload` event fires when the user clicks on the Download button in the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). -The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. See the [example below](#example). +The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerDownloadEventArgs). The event is cancellable and allows the application to set a name of the downloaded file. Do not add the `.pdf` file extension - the component will do that. The default name of the downloaded file is `Document.pdf`. See the [example below](#example). ## OnError diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 4f024b8480..33481848b0 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -19,7 +19,7 @@ To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. 1. Set the `Data` parameter to a byte array that will hold the PDF file contents. -1. (optional) Subscribe to the PDF Viewer's [`OnDownload`]({%slug pdfviewer-events%}#ondownload) or [`OnOpen`]({%slug pdfviewer-events%}#onopen) events, if users will be downloading or opening local files. +1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}) to enhance the user experience. 1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. >caption Basic Blazor PDF Viewer From db112eabcf2b7274f3773da48defdeaffaeb848f Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:38:05 +0300 Subject: [PATCH 07/31] docs(pdfviewer): Random polishing 2 --- components/pdfviewer/overview.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 33481848b0..87dd2312a9 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -19,6 +19,7 @@ To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. 1. Set the `Data` parameter to a byte array that will hold the PDF file contents. +1. If you are developing a Blazor **Server** app, [increase the maximum SignalR message size](#large-file-support). 1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}) to enhance the user experience. 1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. @@ -89,7 +90,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API ## PdfViewer Reference and Methods -The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute. The PdfViewer methods are: +The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: * `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the current file `Data`. From c89c8b4f1145b6567fa0d779af7fb63b02da001d Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:40:11 +0300 Subject: [PATCH 08/31] docs(pdfviewer): Random polishing 3 --- components/pdfviewer/toolbar.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index 7ff3bbbf50..a2100b1d4a 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -48,8 +48,7 @@ Add a `` tag inside the `` tag to: >caption Customize the PDF Viewer toolbar ````CSHTML - + Custom PDF Tool @@ -79,11 +78,6 @@ Add a `` tag inside the `` tag to: { // ... } - - private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) - { - args.FileName = "PDF-Viewer-Download"; - } } ```` From 09c7e62eeb0c7a29362f95b4ea80eca0504cc3f4 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:42:10 +0300 Subject: [PATCH 09/31] docs(pdfviewer): Random polishing 4 --- components/pdfviewer/toolbar.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index a2100b1d4a..1a21b9facb 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -65,8 +65,10 @@ Add a `` tag inside the `` tag to: + + From 85c1d340741c42e6401ab1118c8ae1928c5cd8da Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:22:44 +0300 Subject: [PATCH 10/31] docs(pdfviewer): Remove Page parameter --- components/pdfviewer/overview.md | 1 - 1 file changed, 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 87dd2312a9..b0ff6f7aec 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -83,7 +83,6 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | | `MaxZoom` | `double`
(`4`) | The largest possible zoom in. The default value is 400%. | | `MinZoom` | `double`
(`0.5`) | The largest possible zoom out. The default value is 50%. | -| `Page` | `int`
(`1`) | The current page of the loaded PDF document. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | | `ZoomRate` | `double`
(`0.25`) | The zoom level change that is used by the zoom in and zoom out buttons. | From 14bff153315c5d4416b076340719006a84430976 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:29:04 +0300 Subject: [PATCH 11/31] minor polishing --- components/pdfviewer/toolbar.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index 1a21b9facb..c9753e9390 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -15,7 +15,7 @@ The PDF Viewer toolbar can render built-in and custom tools. This article descri ## Built-in Tools -By default, the PDF Viewer displays all its built-in tools in the listed order below. Use the *tool tag* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-customization). +By default, the PDF Viewer displays all its built-in tools in the order below. Use the *tool tag* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-customization). @[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) @@ -39,7 +39,7 @@ In addition to built-in tools, the PDF Viewer also supports custom tools. Use th ## Toolbar Customization -Add a `` tag inside the `` tag to: +Add a `` tag inside `` to: * Arrange the PDF Viewer tools in a specific order; * Remove some of the built-in tools; From e8d4fde5e9ca358405f2c03374e1ba36a4395bcb Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:30:54 +0300 Subject: [PATCH 12/31] zoom parameter rewording --- components/pdfviewer/overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index b0ff6f7aec..b8d7957240 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -81,8 +81,8 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `Data` | `byte[]` | The source of the currently displayed PDF file. | | `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation for operations that take more than 600 ms. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | -| `MaxZoom` | `double`
(`4`) | The largest possible zoom in. The default value is 400%. | -| `MinZoom` | `double`
(`0.5`) | The largest possible zoom out. The default value is 50%. | +| `MaxZoom` | `double`
(`4`) | The largest possible zoom level. The default value is 400%. | +| `MinZoom` | `double`
(`0.5`) | The smallest possible zoom level. The default value is 50%. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | | `ZoomRate` | `double`
(`0.25`) | The zoom level change that is used by the zoom in and zoom out buttons. | From dc1f8574be159790d7bba79f65e5ddf853689083 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:54:42 +0300 Subject: [PATCH 13/31] docs(pdfviewer): Improve Rebind example --- components/pdfviewer/overview.md | 112 +++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 5 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index b8d7957240..3658d3b3c2 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -91,26 +91,128 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: -* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the current file `Data`. +* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. Such a scenario is simulated in the example below. ->caption PDF Viewer reference and method usage +>caption PDF Viewer reference and Rebind method usage ````CSHTML -Rebind PDF Viewer +@using System.Timers + +@implements IDisposable + + + Rebind PDF Viewer + + @code { private TelerikPdfViewer PdfViewerRef { get; set; } - private byte[] PdfSource { get; set; } - private async Task OnButtonClick() { PdfViewerRef.Rebind(); } + + private byte[] PdfSource + { + get + { + return System.Text.Encoding.UTF8.GetBytes(pdfSourceRaw.Replace("placeholder", "PDF file updated at " + TimeString)); + } + } + + private string TimeString { get; set; } = DateTime.Now.ToLongTimeString(); + + private const int TimerInterval = 1000; + + private Timer PdfTimer { get; set; } = new Timer(); + + protected override void OnAfterRender(bool firstRender) + { + if (PdfTimer.Enabled == false) + { + PdfTimer.Interval = TimerInterval; + PdfTimer.Elapsed -= OnTimerElapsed; + PdfTimer.Elapsed += OnTimerElapsed; + PdfTimer.AutoReset = true; + PdfTimer.Start(); + } + } + + private void OnTimerElapsed(Object source, ElapsedEventArgs e) + { + TimeString = DateTime.Now.ToLongTimeString(); + } + + public void Dispose() + { + PdfTimer.Stop(); + PdfTimer?.Close(); + } + + private string pdfSourceRaw = @"%PDF-1.1 +%¥±ë + +1 0 obj +<< /Type /Catalog +/Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages +/Kids [3 0 R] +/Count 1 +/MediaBox [0 0 300 144] +>> +endobj + +3 0 obj +<< /Type /Page +/Parent 2 0 R +/Resources +<< /Font + << /F1 + << /Type /Font + /Subtype /Type1 + /BaseFont /Times-Roman + >> + >> +>> +/Contents 4 0 R +>> +endobj + +4 0 obj +<< /Length 59 >> +stream +BT +/F1 18 Tf +0 0 Td +(placeholder) Tj +ET +endstream +endobj + +xref +0 5 +0000000000 65535 f +0000000021 00000 n +0000000086 00000 n +0000000195 00000 n +0000000490 00000 n +trailer +<< /Root 1 0 R +/Size 5 +>> +startxref +609 +%%EOF +"; } ```` From 0482b80589a444d93761d403ef3282541b9fe1a9 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:56:42 +0300 Subject: [PATCH 14/31] avoid passive voice --- components/pdfviewer/overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 3658d3b3c2..12a960ee5d 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -91,7 +91,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: -* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. Such a scenario is simulated in the example below. +* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. The following example simulates such scenario. >caption PDF Viewer reference and Rebind method usage From 549e3c4d95998addb2913506ef092f65e8ca4701 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sun, 4 Sep 2022 11:11:45 +0300 Subject: [PATCH 15/31] reduce PDF size, remove Timer --- components/pdfviewer/overview.md | 73 +++++++++----------------------- 1 file changed, 19 insertions(+), 54 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 12a960ee5d..c69a6b0855 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -96,16 +96,13 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a >caption PDF Viewer reference and Rebind method usage ````CSHTML -@using System.Timers - -@implements IDisposable - Rebind PDF Viewer + @@ -121,70 +118,40 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a { get { - return System.Text.Encoding.UTF8.GetBytes(pdfSourceRaw.Replace("placeholder", "PDF file updated at " + TimeString)); + return System.Text.Encoding.UTF8.GetBytes( + PdfSourceRaw.Replace("placeholder", + PdfUpdateFlag ? "PDF file updated at " + DateTime.Now.ToLongTimeString() : "PDF file") + ); } } - private string TimeString { get; set; } = DateTime.Now.ToLongTimeString(); - - private const int TimerInterval = 1000; - - private Timer PdfTimer { get; set; } = new Timer(); - - protected override void OnAfterRender(bool firstRender) + protected override async Task OnInitializedAsync() { - if (PdfTimer.Enabled == false) - { - PdfTimer.Interval = TimerInterval; - PdfTimer.Elapsed -= OnTimerElapsed; - PdfTimer.Elapsed += OnTimerElapsed; - PdfTimer.AutoReset = true; - PdfTimer.Start(); - } - } + await Task.Delay(1000); - private void OnTimerElapsed(Object source, ElapsedEventArgs e) - { - TimeString = DateTime.Now.ToLongTimeString(); - } + PdfUpdateFlag = true; + PdfViewerRef.Rebind(); - public void Dispose() - { - PdfTimer.Stop(); - PdfTimer?.Close(); + await base.OnInitializedAsync(); } - private string pdfSourceRaw = @"%PDF-1.1 + private bool PdfUpdateFlag { get; set; } + + private string PdfSourceRaw = @"%PDF-1.1 %¥±ë 1 0 obj -<< /Type /Catalog -/Pages 2 0 R ->> +<< /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj -<< /Type /Pages -/Kids [3 0 R] -/Count 1 -/MediaBox [0 0 300 144] ->> +<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [-30 -100 270 44] >> endobj 3 0 obj -<< /Type /Page -/Parent 2 0 R -/Resources -<< /Font - << /F1 - << /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman - >> - >> ->> -/Contents 4 0 R ->> +<< /Type /Page /Parent 2 0 R /Resources << /Font << /F1 +<< /Type /Font /Subtype /Type1 /BaseFont /Arial >> +>> >> /Contents 4 0 R >> endobj 4 0 obj @@ -206,9 +173,7 @@ xref 0000000195 00000 n 0000000490 00000 n trailer -<< /Root 1 0 R -/Size 5 ->> +<< /Root 1 0 R /Size 5 >> startxref 609 %%EOF From b1c27c88ff49adb39e61c6f5c47da13c350f7737 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sun, 4 Sep 2022 21:10:05 +0300 Subject: [PATCH 16/31] simplify PDF source in the basic example --- components/pdfviewer/overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index c69a6b0855..aaefb0b030 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -46,7 +46,7 @@ To use a Telerik PDF Viewer for Blazor: base.OnInitialized(); } - private string SamplePdf { get; set; } = @"JVBERi0xLjENCiXCpcKxw6sNCg0KMSAwIG9iag0KICA8PCAvVHlwZSAvQ2F0YWxvZw0KICAgICAvUGFnZXMgMiAwIFINCiAgPj4NCmVuZG9iag0KDQoyIDAgb2JqDQogIDw8IC9UeXBlIC9QYWdlcw0KICAgICAvS2lkcyBbMyAwIFJdDQogICAgIC9Db3VudCAxDQogICAgIC9NZWRpYUJveCBbMCAwIDMwMCAxNDRdDQogID4+DQplbmRvYmoNCg0KMyAwIG9iag0KICA8PCAgL1R5cGUgL1BhZ2UNCiAgICAgIC9QYXJlbnQgMiAwIFINCiAgICAgIC9SZXNvdXJjZXMNCiAgICAgICA8PCAvRm9udA0KICAgICAgICAgICA8PCAvRjENCiAgICAgICAgICAgICAgIDw8IC9UeXBlIC9Gb250DQogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTENCiAgICAgICAgICAgICAgICAgIC9CYXNlRm9udCAvVGltZXMtUm9tYW4NCiAgICAgICAgICAgICAgID4+DQogICAgICAgICAgID4+DQogICAgICAgPj4NCiAgICAgIC9Db250ZW50cyA0IDAgUg0KICA+Pg0KZW5kb2JqDQoNCjQgMCBvYmoNCiAgPDwgL0xlbmd0aCA1OSA+Pg0Kc3RyZWFtDQogIEJUDQogICAgL0YxIDE4IFRmDQogICAgMCAwIFRkDQogICAgKFRlbGVyaWsgUGRmVmlld2VyIGZvciBCbGF6b3IpIFRqDQogIEVUDQplbmRzdHJlYW0NCmVuZG9iag0KDQp4cmVmDQowIDUNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAyMSAwMDAwMCBuDQowMDAwMDAwMDg2IDAwMDAwIG4NCjAwMDAwMDAxOTUgMDAwMDAgbg0KMDAwMDAwMDQ5MCAwMDAwMCBuDQp0cmFpbGVyDQogIDw8ICAvUm9vdCAxIDAgUg0KICAgICAgL1NpemUgNQ0KICA+Pg0Kc3RhcnR4cmVmDQo2MDkNCiUlRU9GDQo="; + private string SamplePdf { get; set; } = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; } ```` From acb773264c9d0de3fff417a31f36314088b502f3 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sun, 4 Sep 2022 21:20:02 +0300 Subject: [PATCH 17/31] simplify Rebind example --- components/pdfviewer/overview.md | 36 ++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index aaefb0b030..fd330d7267 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -102,7 +102,6 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a Rebind PDF Viewer -
@@ -119,8 +118,8 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a get { return System.Text.Encoding.UTF8.GetBytes( - PdfSourceRaw.Replace("placeholder", - PdfUpdateFlag ? "PDF file updated at " + DateTime.Now.ToLongTimeString() : "PDF file") + PdfSourceRaw.Replace("...", + PdfUpdateFlag ? "updated at " + DateTime.Now.ToLongTimeString() : "") ); } } @@ -138,33 +137,18 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a private bool PdfUpdateFlag { get; set; } private string PdfSourceRaw = @"%PDF-1.1 -%¥±ë - -1 0 obj -<< /Type /Catalog /Pages 2 0 R >> -endobj - -2 0 obj -<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [-30 -100 270 44] >> -endobj - -3 0 obj -<< /Type /Page /Parent 2 0 R /Resources << /Font << /F1 -<< /Type /Font /Subtype /Type1 /BaseFont /Arial >> ->> >> /Contents 4 0 R >> -endobj - -4 0 obj -<< /Length 59 >> +1 0 obj<>endobj +2 0 obj<>endobj +3 0 obj<> >> >>/Contents 4 0 R>>endobj +4 0 obj<> stream BT /F1 18 Tf 0 0 Td -(placeholder) Tj +(PDF File ...) Tj ET endstream endobj - xref 0 5 0000000000 65535 f @@ -172,12 +156,10 @@ xref 0000000086 00000 n 0000000195 00000 n 0000000490 00000 n -trailer -<< /Root 1 0 R /Size 5 >> +trailer << /Root 1 0 R /Size 5 >> startxref 609 -%%EOF -"; +%%EOF"; } ```` From 7ff6cb42dd9d38cb15c8efd1e9e2b569f90e6b70 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sun, 4 Sep 2022 21:36:05 +0300 Subject: [PATCH 18/31] polishing --- components/pdfviewer/overview.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index fd330d7267..c450fc4ce7 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -20,7 +20,7 @@ To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. 1. Set the `Data` parameter to a byte array that will hold the PDF file contents. 1. If you are developing a Blazor **Server** app, [increase the maximum SignalR message size](#large-file-support). -1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}) to enhance the user experience. +1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}). For example, the `OnDownload` event handler sets the name of the downloaded file. 1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. >caption Basic Blazor PDF Viewer @@ -41,12 +41,12 @@ To use a Telerik PDF Viewer for Blazor: protected override void OnInitialized() { - PdfSource = Convert.FromBase64String(SamplePdf); + PdfSource = Convert.FromBase64String(PdfBase64); base.OnInitialized(); } - private string SamplePdf { get; set; } = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; + private string PdfBase64 { get; set; } = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; } ```` @@ -79,7 +79,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | --- | --- | --- | | `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | | `Data` | `byte[]` | The source of the currently displayed PDF file. | -| `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation for operations that take more than 600 ms. | +| `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening or downloading a PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | | `MaxZoom` | `double`
(`4`) | The largest possible zoom level. The default value is 400%. | | `MinZoom` | `double`
(`0.5`) | The smallest possible zoom level. The default value is 50%. | From 3c86b7f55ad38940feebf0a10ec254d7d1578df0 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:05:42 +0300 Subject: [PATCH 19/31] docs(pdfviewer): Add Zoom/ZoomChanged + polishing --- components/pdfviewer/events.md | 20 ++++++++++++++++++-- components/pdfviewer/overview.md | 11 +++++++---- components/pdfviewer/toolbar.md | 8 ++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index 5a53d31751..41cf08d6ba 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -1,7 +1,7 @@ --- title: Events page_title: PdfViewer - Events -description: Events of the PDF Viewer for Blazor. +description: Events of the PDF Viewer for Blazor. How to handle events when users download, open or zoom PDF documents. slug: pdfviewer-events tags: telerik,blazor,pdf,pdfviewer published: True @@ -15,6 +15,7 @@ This article describes the Blazor PDF Viewer events and provides a runnable exam * [`OnDownload`](#ondownload) * [`OnError`](#onerror) * [`OnOpen`](#onopen) +* [`ZoomChanged`](#zoomchanged) ## OnDownload @@ -37,6 +38,12 @@ The `OnOpen` event fires when the user selects a file to open from the [PDF View The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. See the [example below](#example). +## ZoomChanged + +The `ZoomChanged` event fires when the user clicks on the zoom in/out buttons, or selects a new zoom level from the ComboBox. + +The event handler receives the new zoom level as an argument of type `double`. To apply the new zoom level, set it as a new `Zoom` parameter value. Not setting it will effectively cancel the event. + ## Example @@ -51,12 +58,16 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo OnDownload="@OnPdfDownload" OnError="@OnPdfError" OnOpen="@OnPdfOpen" + Zoom="@PdfZoom" + ZoomChanged="@OnPdfZoomChanged" Height="600px"> @code { private byte[] PdfSource { get; set; } + private double PdfZoom { get; set; } = 1.25; + private string PdfName { get; set; } = "..."; private long PdfSize { get; set; } @@ -98,6 +109,11 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo EventLog = "Open successful."; } } + + private async Task OnPdfZoomChanged(double newZoom) + { + PdfZoom = newZoom; + } } ```` @@ -109,5 +125,5 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo ## See Also -* [PdfViewer Live Demo](https://demos.telerik.com/blazor-ui/pdfviewer/overview) +* [PdfViewer Events Demo](https://demos.telerik.com/blazor-ui/pdfviewer/events) * [PdfViewer API](/blazor-ui/api/Telerik.Blazor.Components.TelerikPdfViewer) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index c450fc4ce7..ebae18556a 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -10,7 +10,7 @@ position: 0 # Blazor PdfViewer Overview -The
Pdf Viewer for Blazor allows users to open PDF files directly in the browser. The component provides all major features, such as paging, zooming and printing. In addition, users can upload and display a PDF file from their local device, or download the currently open file. +The Pdf Viewer for Blazor allows users to open PDF files directly in the browser. The component provides features such as paging, zooming, printing, text selection and search. In addition, users can upload and display a PDF file from their local device, or download the currently open file. ## Creating Blazor PdfViewer @@ -18,9 +18,9 @@ The Pdf To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. -1. Set the `Data` parameter to a byte array that will hold the PDF file contents. +1. Set the `Data` parameter to a byte array `byte[]` that will hold the PDF file contents. 1. If you are developing a Blazor **Server** app, [increase the maximum SignalR message size](#large-file-support). -1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}). For example, the `OnDownload` event handler sets the name of the downloaded file. +1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}). For example, use the `OnDownload` event to set the name of the downloaded file. 1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. >caption Basic Blazor PDF Viewer @@ -84,6 +84,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `MaxZoom` | `double`
(`4`) | The largest possible zoom level. The default value is 400%. | | `MinZoom` | `double`
(`0.5`) | The smallest possible zoom level. The default value is 50%. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | +| `Zoom` | `double`
(`1.25`) | The current zoom level. Use the parameter with two-way binding or with a [`ZoomChanged` event handler]({%slug pdfviewer-events%}#zoomchanged). | | `ZoomRate` | `double`
(`0.25`) | The zoom level change that is used by the zoom in and zoom out buttons. | @@ -91,7 +92,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: -* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. The following example simulates such scenario. +* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. >caption PDF Viewer reference and Rebind method usage @@ -128,7 +129,9 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a { await Task.Delay(1000); + // PdfUpdateFlag is used in the PdfSource getter to make the document change more obvious PdfUpdateFlag = true; + PdfViewerRef.Rebind(); await base.OnInitializedAsync(); diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index c9753e9390..a5db9adfa5 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -1,7 +1,7 @@ --- title: Toolbar page_title: PdfViewer - Toolbar -description: Toolbar of the PDF Viewer for Blazor. +description: Toolbar of the PDF Viewer for Blazor. List of all built-in tools. How to use custom PDF Viewer tools. slug: pdfviewer-toolbar tags: telerik,blazor,pdf,pdfviewer published: True @@ -15,7 +15,7 @@ The PDF Viewer toolbar can render built-in and custom tools. This article descri ## Built-in Tools -By default, the PDF Viewer displays all its built-in tools in the order below. Use the *tool tag* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-customization). +By default, the PDF Viewer displays all its built-in tools in the order below. Use the *tool tag name* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-configuration). @[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) @@ -37,9 +37,9 @@ The default toolbar user interface also includes separators (`` tag, which is a standard Blazor `RenderFragment`. Render the desired custom tool UI as `ChildContent` inside the tag. -## Toolbar Customization +## Toolbar Configuration -Add a `` tag inside `` to: +Add a `` tag inside `` to configure a custom toolbar, for example: * Arrange the PDF Viewer tools in a specific order; * Remove some of the built-in tools; From 8e3020ccf2c43bd740222492221711b3185d8be6 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 22:00:18 +0300 Subject: [PATCH 20/31] Replace PDF source string with base64 string --- components/pdfviewer/overview.md | 32 ++++++-------------------------- components/pdfviewer/toolbar.md | 2 +- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index ebae18556a..f432021414 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -56,9 +56,8 @@ To use a Telerik PDF Viewer for Blazor: The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools are related to the built-in features such as: * Paging -* Zoom * Text selection -* Pan +* Zoom and pan * Search * Open and download * Print @@ -127,6 +126,8 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a protected override async Task OnInitializedAsync() { + PdfSourceRaw = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(PdfSourceBase64)); + await Task.Delay(1000); // PdfUpdateFlag is used in the PdfSource getter to make the document change more obvious @@ -139,30 +140,9 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a private bool PdfUpdateFlag { get; set; } - private string PdfSourceRaw = @"%PDF-1.1 -1 0 obj<>endobj -2 0 obj<>endobj -3 0 obj<> >> >>/Contents 4 0 R>>endobj -4 0 obj<> -stream -BT -/F1 18 Tf -0 0 Td -(PDF File ...) Tj -ET -endstream -endobj -xref -0 5 -0000000000 65535 f -0000000021 00000 n -0000000086 00000 n -0000000195 00000 n -0000000490 00000 n -trailer << /Root 1 0 R /Size 5 >> -startxref -609 -%%EOF"; + private string PdfSourceRaw { get; set; } + + private string PdfSourceBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy0zMCAtNjQgMjcwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihQREYgRmlsZSAuLi4pIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDg2IDAwMDAwIG4KMDAwMDAwMDE5NSAwMDAwMCBuCjAwMDAwMDA0OTAgMDAwMDAgbgp0cmFpbGVyIDw8ICAvUm9vdCAxIDAgUiAvU2l6ZSA1ID4+CnN0YXJ0eHJlZgo2MDkKJSVFT0Y="; } ```` diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index a5db9adfa5..1dd8e99aa1 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -78,7 +78,7 @@ Add a `` tag inside `` to configure a custom private async Task OnPdfCustomClick() { - // ... + Console.Writeline("Custom PDF tool clicked"); } } ```` From 08fd39849850ac55da8df6d804392d20a2519a76 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 22:08:32 +0300 Subject: [PATCH 21/31] polshing --- components/pdfviewer/overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index f432021414..321a151b81 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -78,7 +78,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | --- | --- | --- | | `Class` | `string` | An additional CSS class for the `
` element. Use it to [customize the component styles and override the theme]({%slug themes-override%}). | | `Data` | `byte[]` | The source of the currently displayed PDF file. | -| `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening or downloading a PDF file. | +| `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening, downloading or zooming a PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | | `MaxZoom` | `double`
(`4`) | The largest possible zoom level. The default value is 400%. | | `MinZoom` | `double`
(`0.5`) | The smallest possible zoom level. The default value is 50%. | @@ -91,7 +91,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: -* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when changes to the PDF file source can occur behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. +* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when the PDF file source changes behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. >caption PDF Viewer reference and Rebind method usage From b56697445bcfa99865d182fdb49fb4495d394026 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 22:11:09 +0300 Subject: [PATCH 22/31] smaller feature list in Overview --- components/pdfviewer/overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 321a151b81..1b0a3f9c56 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -57,10 +57,10 @@ The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-to * Paging * Text selection -* Zoom and pan * Search -* Open and download * Print +* Zoom and pan +* Open and download ## Large File Support From a5cbae8dae00773f713a49e100ad7a6dfae7f443 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 22:13:30 +0300 Subject: [PATCH 23/31] use consistent variable naming --- components/pdfviewer/overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 1b0a3f9c56..c941eabb00 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -126,7 +126,7 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a protected override async Task OnInitializedAsync() { - PdfSourceRaw = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(PdfSourceBase64)); + PdfSourceRaw = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(PdfBase64)); await Task.Delay(1000); @@ -142,7 +142,7 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a private string PdfSourceRaw { get; set; } - private string PdfSourceBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy0zMCAtNjQgMjcwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihQREYgRmlsZSAuLi4pIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDg2IDAwMDAwIG4KMDAwMDAwMDE5NSAwMDAwMCBuCjAwMDAwMDA0OTAgMDAwMDAgbgp0cmFpbGVyIDw8ICAvUm9vdCAxIDAgUiAvU2l6ZSA1ID4+CnN0YXJ0eHJlZgo2MDkKJSVFT0Y="; + private string PdfBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy0zMCAtNjQgMjcwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihQREYgRmlsZSAuLi4pIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDg2IDAwMDAwIG4KMDAwMDAwMDE5NSAwMDAwMCBuCjAwMDAwMDA0OTAgMDAwMDAgbgp0cmFpbGVyIDw8ICAvUm9vdCAxIDAgUiAvU2l6ZSA1ID4+CnN0YXJ0eHJlZgo2MDkKJSVFT0Y="; } ```` From 7eb3e879f7fb6591874bb67dca7d20bbfb45eb03 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Fri, 9 Sep 2022 22:27:19 +0300 Subject: [PATCH 24/31] use const --- components/pdfviewer/overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index c941eabb00..a859c01c4e 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -46,7 +46,7 @@ To use a Telerik PDF Viewer for Blazor: base.OnInitialized(); } - private string PdfBase64 { get; set; } = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; + private const string PdfBase64 = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; } ```` @@ -142,7 +142,7 @@ The PdfViewer exposes methods for programmatic operation. To use them, define a private string PdfSourceRaw { get; set; } - private string PdfBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy0zMCAtNjQgMjcwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihQREYgRmlsZSAuLi4pIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDg2IDAwMDAwIG4KMDAwMDAwMDE5NSAwMDAwMCBuCjAwMDAwMDA0OTAgMDAwMDAgbgp0cmFpbGVyIDw8ICAvUm9vdCAxIDAgUiAvU2l6ZSA1ID4+CnN0YXJ0eHJlZgo2MDkKJSVFT0Y="; + private const string PdfBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy0zMCAtNjQgMjcwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihQREYgRmlsZSAuLi4pIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDg2IDAwMDAwIG4KMDAwMDAwMDE5NSAwMDAwMCBuCjAwMDAwMDA0OTAgMDAwMDAgbgp0cmFpbGVyIDw8ICAvUm9vdCAxIDAgUiAvU2l6ZSA1ID4+CnN0YXJ0eHJlZgo2MDkKJSVFT0Y="; } ```` From 47ab86217f82d24ca7f50e2ccf9a0f8cc2880a9e Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 10 Sep 2022 13:41:01 +0300 Subject: [PATCH 25/31] reword feature list --- components/pdfviewer/overview.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index a859c01c4e..d5ad00df3c 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -53,14 +53,11 @@ To use a Telerik PDF Viewer for Blazor: ## Toolbar -The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools are related to the built-in features such as: - -* Paging -* Text selection -* Search -* Print -* Zoom and pan -* Open and download +The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools enable the built-in features such as: + +* Page, zoom and pan documents +* Search and select text +* Print, download and open local PDF files ## Large File Support From 635c73cc2509db89c72995047a91f4e1781d3990 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Sat, 10 Sep 2022 16:46:27 +0300 Subject: [PATCH 26/31] polishing and refactoring --- components/pdfviewer/events.md | 44 +++++++++++++++++--------------- components/pdfviewer/overview.md | 17 +++++++----- components/pdfviewer/toolbar.md | 19 +++++++------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index 41cf08d6ba..120f2a28f7 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -36,7 +36,8 @@ The event handler receives an argument of type [`PdfViewerErrorEventArgs`](/blaz The `OnOpen` event fires when the user selects a file to open from the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). -The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. See the [example below](#example). +The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. The `OnOpen` handler is not required to open a file. See the [example below](#example). + ## ZoomChanged @@ -50,17 +51,17 @@ The event handler receives the new zoom level as an argument of type `double`. T >caption Handle or cancel Blazor PDF Viewer Events ````CSHTML -

Last opened file by the user: @PdfName, with size @PdfSize.ToString() bytes.

-

Last event: @EventLog

+

+ + ZoomChanged="@OnPdfZoomChanged"> @code { @@ -68,51 +69,54 @@ The event handler receives the new zoom level as an argument of type `double`. T private double PdfZoom { get; set; } = 1.25; - private string PdfName { get; set; } = "..."; - - private long PdfSize { get; set; } + private bool AllowDownloads { get; set; } = true; private string EventLog { get; set; } = "..."; private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) { - //args.IsCancelled = true; - args.FileName = "PDF-Viewer-Download"; - EventLog = "Download successful."; + if (AllowDownloads) + { + args.FileName = "PDF-Viewer-Download"; + EventLog = $"Download {args.FileName}.pdf"; + } + else + { + args.IsCancelled = true; + EventLog = $"Download cancelled"; + } } private async Task OnPdfError(PdfViewerErrorEventArgs args) { - // Rename a random non-PDF file to error.pdf and try to open it. - EventLog = "Open failed. The Error message was: " + args.Message; + // To trigger the event, rename a random file to error.pdf and try to open it. + EventLog = "Error: " + args.Message; } private async Task OnPdfOpen(PdfViewerOpenEventArgs args) { var file = args.Files.FirstOrDefault(); - if (file.Size > 1_000_000) + if (file.Size > 1024 * 1024) { args.IsCancelled = true; - EventLog = "Open rejected. File too large."; + EventLog = $"Open cancelled conditionally. File {file.Name} ({file.Size} bytes) is larger than 1 MB."; } else { - PdfName = file.Name; - PdfSize = file.Size; - // Get the PDF file contents if necessary. - // It is not necessary to set the Data parameter value here. var buffer = new byte[file.Stream.Length]; await file.Stream.ReadAsync(buffer); - EventLog = "Open successful."; + EventLog = $"Open {file.Name}, {file.Size} bytes"; } } private async Task OnPdfZoomChanged(double newZoom) { PdfZoom = newZoom; + + EventLog = "Zoom level changed."; } } ```` diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index d5ad00df3c..0eb083155b 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -10,7 +10,7 @@ position: 0 # Blazor PdfViewer Overview -The
Pdf Viewer for Blazor allows users to open PDF files directly in the browser. The component provides features such as paging, zooming, printing, text selection and search. In addition, users can upload and display a PDF file from their local device, or download the currently open file. +The Pdf Viewer for Blazor allows users to open PDF files directly in the browser. The component provides features such as paging, zooming, printing, text selection and search. In addition, users can upload and display a PDF file from their local device, or download the currently open file. ## Creating Blazor PdfViewer @@ -18,7 +18,7 @@ The Pdf To use a Telerik PDF Viewer for Blazor: 1. Add the `TelerikPdfViewer` tag. -1. Set the `Data` parameter to a byte array `byte[]` that will hold the PDF file contents. +1. Set the `Data` parameter to a byte array (`byte[]`) that holds the PDF file contents. 1. If you are developing a Blazor **Server** app, [increase the maximum SignalR message size](#large-file-support). 1. (optional) Subscribe to the [PDF Viewer's events]({%slug pdfviewer-events%}). For example, use the `OnDownload` event to set the name of the downloaded file. 1. (optional) Set [`Width` or `Height`](#pdfviewer-parameters) for the component. @@ -46,14 +46,14 @@ To use a Telerik PDF Viewer for Blazor: base.OnInitialized(); } - private const string PdfBase64 = @"JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; + private const string PdfBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G"; } ```` ## Toolbar -The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools enable the built-in features such as: +The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-toolbar%}). The default tools enable built-in features such as: * Page, zoom and pan documents * Search and select text @@ -86,9 +86,14 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API ## PdfViewer Reference and Methods -The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. The PdfViewer methods are: +The PdfViewer exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Method | Description | +| --- | --- | +| `Rebind` | Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. [`Rebind` is necessary when the Blazor framework cannot re-render components automatically]({%slug common-features-data-binding-overview%}#refresh-data). | -* `Rebind` - Refreshes the PDF Viewer and ensures it is displaying the latest file `Data`. Use `Rebind()` when the PDF file source changes behind the scenes and the Blazor framework does not re-render the PDF Viewer automatically. >caption PDF Viewer reference and Rebind method usage diff --git a/components/pdfviewer/toolbar.md b/components/pdfviewer/toolbar.md index 1dd8e99aa1..3bdee10a43 100644 --- a/components/pdfviewer/toolbar.md +++ b/components/pdfviewer/toolbar.md @@ -15,7 +15,7 @@ The PDF Viewer toolbar can render built-in and custom tools. This article descri ## Built-in Tools -By default, the PDF Viewer displays all its built-in tools in the order below. Use the *tool tag name* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-configuration). +By default, the PDF Viewer displays all its built-in tools in the order below. Use the *tool tag* if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-configuration). @[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) @@ -29,12 +29,12 @@ By default, the PDF Viewer displays all its built-in tools in the order below. U | Download | `PdfViewerToolBarDownloadTool` | A download button. It fires the [`OnDownload` event]({%slug pdfviewer-events%}#ondownload). | | Print | `PdfViewerToolBarPrintTool` | A print button. | -The default toolbar user interface also includes separators (``) and spacers (``). The separators render as a vertical line. Spacers consume the available empty space and push the rest of the tools next to one another. +By default, the toolbar also includes separators (``) and spacers (``). Separators render as a vertical line. Spacers consume the available empty space and push the rest of the tools next to one another. ## Custom Tools -In addition to built-in tools, the PDF Viewer also supports custom tools. Use the `` tag, which is a standard Blazor `RenderFragment`. Render the desired custom tool UI as `ChildContent` inside the tag. +In addition to built-in tools, the PDF Viewer also supports custom tools. Use the `` tag, which is a standard Blazor `RenderFragment`. See the example below. ## Toolbar Configuration @@ -56,20 +56,19 @@ Add a `` tag inside `` to configure a custom - + + - + - - - - + + @@ -78,7 +77,7 @@ Add a `` tag inside `` to configure a custom private async Task OnPdfCustomClick() { - Console.Writeline("Custom PDF tool clicked"); + Console.WriteLine("Custom PDF tool clicked"); } } ```` From 31dba64bb86c042642a267f4db46752f045acafa Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:09:34 +0300 Subject: [PATCH 27/31] switch form double to decimal --- components/pdfviewer/events.md | 6 +++--- components/pdfviewer/overview.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index 120f2a28f7..f47907f38e 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -43,7 +43,7 @@ The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazo The `ZoomChanged` event fires when the user clicks on the zoom in/out buttons, or selects a new zoom level from the ComboBox. -The event handler receives the new zoom level as an argument of type `double`. To apply the new zoom level, set it as a new `Zoom` parameter value. Not setting it will effectively cancel the event. +The event handler receives the new zoom level as an argument of type `decimal`. To apply the new zoom level, set it as a new `Zoom` parameter value. Not setting it will effectively cancel the event. ## Example @@ -67,7 +67,7 @@ The event handler receives the new zoom level as an argument of type `double`. T @code { private byte[] PdfSource { get; set; } - private double PdfZoom { get; set; } = 1.25; + private decimal PdfZoom { get; set; } = 1.25m; private bool AllowDownloads { get; set; } = true; @@ -112,7 +112,7 @@ The event handler receives the new zoom level as an argument of type `double`. T } } - private async Task OnPdfZoomChanged(double newZoom) + private async Task OnPdfZoomChanged(decimal newZoom) { PdfZoom = newZoom; diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 0eb083155b..09ec5c4e56 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -77,11 +77,11 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `Data` | `byte[]` | The source of the currently displayed PDF file. | | `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening, downloading or zooming a PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | -| `MaxZoom` | `double`
(`4`) | The largest possible zoom level. The default value is 400%. | -| `MinZoom` | `double`
(`0.5`) | The smallest possible zoom level. The default value is 50%. | +| `MaxZoom` | `decimal`
(`4m`) | The largest possible zoom level. The default value is 400%. | +| `MinZoom` | `decimal`
(`0.5m`) | The smallest possible zoom level. The default value is 50%. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | -| `Zoom` | `double`
(`1.25`) | The current zoom level. Use the parameter with two-way binding or with a [`ZoomChanged` event handler]({%slug pdfviewer-events%}#zoomchanged). | -| `ZoomRate` | `double`
(`0.25`) | The zoom level change that is used by the zoom in and zoom out buttons. | +| `Zoom` | `decimal`
(`1.25m`) | The current zoom level. Use the parameter with two-way binding or with a [`ZoomChanged` event handler]({%slug pdfviewer-events%}#zoomchanged). | +| `ZoomRate` | `decimal`
(`0.25m`) | The zoom level change that is used by the zoom in and zoom out buttons. | ## PdfViewer Reference and Methods From 478fbaa2070b8247c321af51f29bbe2ba8a5ab42 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:44:57 +0300 Subject: [PATCH 28/31] Update components/pdfviewer/overview.md --- components/pdfviewer/overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 09ec5c4e56..51e59ae71c 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -77,7 +77,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `Data` | `byte[]` | The source of the currently displayed PDF file. | | `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening, downloading or zooming a PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | -| `MaxZoom` | `decimal`
(`4m`) | The largest possible zoom level. The default value is 400%. | +| `MaxZoom` | `decimal`
(`4m`) | The largest possible zoom level. The default value allows zooming in 4 times (400%). | | `MinZoom` | `decimal`
(`0.5m`) | The smallest possible zoom level. The default value is 50%. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | | `Zoom` | `decimal`
(`1.25m`) | The current zoom level. Use the parameter with two-way binding or with a [`ZoomChanged` event handler]({%slug pdfviewer-events%}#zoomchanged). | From 540802c45c3d4bcc1b804f44225e38365a2cce51 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:45:40 +0300 Subject: [PATCH 29/31] Update components/pdfviewer/overview.md --- components/pdfviewer/overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 51e59ae71c..0984baf22c 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -78,7 +78,7 @@ The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API | `EnableLoaderContainer` | `bool`
(`true`) | Determines if the PDF Viewer will show a loading animation during opening, downloading or zooming a PDF file. | | `Height` | `string` | The PdfViewer height as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand vertically, based on the loaded file. `Height` is required for the component paging and scrolling to work. | | `MaxZoom` | `decimal`
(`4m`) | The largest possible zoom level. The default value allows zooming in 4 times (400%). | -| `MinZoom` | `decimal`
(`0.5m`) | The smallest possible zoom level. The default value is 50%. | +| `MinZoom` | `decimal`
(`0.5m`) | The smallest possible zoom level. The default value allows zooming out to 50%. | | `Width` | `string` | The PdfViewer width as a [CSS length value]({%slug common-features/dimensions%}). If not set, the component will expand horizontally to fill its parent. | | `Zoom` | `decimal`
(`1.25m`) | The current zoom level. Use the parameter with two-way binding or with a [`ZoomChanged` event handler]({%slug pdfviewer-events%}#zoomchanged). | | `ZoomRate` | `decimal`
(`0.25m`) | The zoom level change that is used by the zoom in and zoom out buttons. | From 0992fd88496d4444bf4709acb9ea71e2a4378e90 Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Tue, 13 Sep 2022 10:54:24 +0300 Subject: [PATCH 30/31] Revamp SignalR information --- components/pdfviewer/events.md | 4 +++- components/pdfviewer/overview.md | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index f47907f38e..d5e0befbbf 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -36,7 +36,9 @@ The event handler receives an argument of type [`PdfViewerErrorEventArgs`](/blaz The `OnOpen` event fires when the user selects a file to open from the [PDF Viewer toolbar]({%slug pdfviewer-toolbar%}). -The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. The `OnOpen` handler is not required to open a file. See the [example below](#example). +The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. To read the `Stream`, you may need to [increase the maximum SignalR message size]({%slug pdfviewer-overview%}#large-file-support). + +The `OnOpen` handler is *not* required to open a file. See the [example below](#example). ## ZoomChanged diff --git a/components/pdfviewer/overview.md b/components/pdfviewer/overview.md index 0984baf22c..d1d53ffdbf 100644 --- a/components/pdfviewer/overview.md +++ b/components/pdfviewer/overview.md @@ -62,7 +62,12 @@ The [PdfViewer toolbar can render built-in and custom tools]({%slug pdfviewer-to ## Large File Support -The PDF Viewer uses a [FileSelect component]({%slug fileselect-overview%}) to open files from the user device. In Blazor **Server** apps, the FileSelect uses the **SignalR WebSocket**, which has a default maximum message size of **32 KB**. To work with larger files, [increase the max WebSocket message size for the Blazor application]({%slug fileselect-overview%}#large-file-support). +In Blazor **Server** apps, the PDF Viewer uses the **SignalR WebSocket** to: + +* Open PDF files from the server and send them to the browser. +* Read the PDF file `Stream` from the user device in the [`OnOpen` event handler]({%slug pdfviewer-events%}#onopen). The PDF Viewer uses internally a [FileSelect component]({%slug fileselect-overview%}) to get the user file. + +The SignalR WebSocket has a default maximum message size of **32 KB**. To work with larger files in the above two scenarios, [increase the max WebSocket message size for the Blazor application]({%slug fileselect-overview%}#large-file-support). ## PdfViewer Parameters From 32648845912784ae29741af3cdba5b68c9b2915b Mon Sep 17 00:00:00 2001 From: Dimo Dimov <961014+dimodi@users.noreply.github.com> Date: Tue, 13 Sep 2022 13:55:16 +0300 Subject: [PATCH 31/31] clarify OnOpen --- components/pdfviewer/events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/pdfviewer/events.md b/components/pdfviewer/events.md index d5e0befbbf..5d40df3e70 100644 --- a/components/pdfviewer/events.md +++ b/components/pdfviewer/events.md @@ -38,7 +38,7 @@ The `OnOpen` event fires when the user selects a file to open from the [PDF View The event handler receives an argument of type [`PdfViewerOpenEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.PdfViewerOpenEventArgs). The event is cancellable and allows the application to obtain the PDF file name, size and contents as a `Stream`. To read the `Stream`, you may need to [increase the maximum SignalR message size]({%slug pdfviewer-overview%}#large-file-support). -The `OnOpen` handler is *not* required to open a file. See the [example below](#example). +Using `OnOpen` is *not* required. Users can open local files from their devices without this handler. See the [example below](#example). ## ZoomChanged