# PdfViewer Events

This article describes the [Blazor PDF Viewer](https://demos.telerik.com/blazor-ui/pdfviewer/overview) events and provides a runnable example with sample event handler implementations.

* [`OnDownload`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#ondownload)
* [`OnError`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#onerror)
* [`OnOpen`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#onopen)
* [`ZoomChanged`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#zoomchanged)

## OnDownload

The `OnDownload` event fires when the user clicks on the Download button in the [PDF Viewer toolbar](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/toolbar).

The event handler receives an argument of type [`PdfViewerDownloadEventArgs`](https://www.telerik.com/blazor-ui/documentation/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](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#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`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.pdfviewererroreventargs), which exposes a `Message` property. See the [example below](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#example).

## OnOpen

The `OnOpen` event fires when the user selects a file to open from the [PDF Viewer toolbar](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/toolbar).

The event handler receives an argument of type [`PdfViewerOpenEventArgs`](https://www.telerik.com/blazor-ui/documentation/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](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#large-file-support).

Using `OnOpen` is *not* required. Users can open local files from their devices without this handler. See the [example below](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#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 resolved zoom level as an argument of type `object`. The value is always a `decimal` (e.g., `1.25m` for 125%), regardless of whether a `PdfViewerZoomLevelType` value was set as the initial `Zoom`. To apply the new zoom level, set it as a new `Zoom` parameter value. Not setting it will effectively cancel the event.

Casting the argument with `(decimal)newZoom` is safe after the initial render.

## Example

> caption Handle or cancel Blazor PDF Viewer Events

<demo metaUrl="client/pdfviewer/events/" height="750"></demo>

## Next Steps

* [Customize the PDF Viewer toolbar](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/toolbar)

## See Also

* [PdfViewer Events Demo](https://demos.telerik.com/blazor-ui/pdfviewer/events)
* [PdfViewer API](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikpdfviewer)
