# Blazor PdfViewer Overview

The <a href = "https://demos.telerik.com/blazor-ui/pdfviewer/overview" target="_blank">Pdf Viewer for Blazor</a> 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

To use a Telerik [Blazor PDF Viewer](https://demos.telerik.com/blazor-ui/pdfviewer/overview):

1. Add the `TelerikPdfViewer` tag.
2. Set the `Data` parameter to a byte array (`byte[]`) that holds the PDF file contents.
3. If you are developing a [Blazor **Server**](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) app, [increase the maximum SignalR message size](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#large-file-support).
4. (optional) Subscribe to the [PDF Viewer's events](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events). For example, use the `OnDownload` event to set the name of the downloaded file.
5. (optional) Set [`Width` or `Height`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#pdfviewer-parameters) for the component.

> caption Basic Blazor PDF Viewer

<demo metaUrl="client/pdfviewer/overview/" height="500"></demo>

## Toolbar

The [PdfViewer toolbar can render built-in and custom tools](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/toolbar). The default tools enable built-in features such as:

* Page, zoom and pan documents
* Search and select text
* Print, download and open local PDF files

## Pinch-to-Zoom

The Telerik PdfViewer supports built-in pinch-to-zoom gestures for touch devices, including mobile phones, tablets, and touchscreen computers. This behavior is enabled by default and works in modern mobile browsers that support the Touch Events API.

Pinch-to-zoom complements the toolbar zoom tools and provides a more natural touch interaction than step-based zoom buttons. Gesture-based and toolbar zoom operations both respect the configured [`MinZoom`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#pdfviewer-parameters) and [`MaxZoom`](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#pdfviewer-parameters) values.

<demo metaUrl="client/pdfviewer/pinch-to-zoom/" height="1000"></demo>

## Annotations

The PdfViewer provides a built-in option for creating and editing annotations. Explore the [available annotation types and how to work with them](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/annotations).

## Form Filling

The PdfViewer supports interactive form filling in PDF documents. You can display and edit form fields such as text boxes, checkboxes, radio buttons, and dropdowns. For more details and examples, see the [Form Filling documentation](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/form-filling).

## Large File Support

In [Blazor **Server**](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) 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](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#onopen). The PDF Viewer uses internally a [FileSelect component](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview) to get the user file.
* Get the loaded or edited PDF file from the browser to the .NET runtime when using the [`GetFileAsync()` method](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/overview#pdfviewer-reference-and-methods).

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](https://www.telerik.com/blazor-ui/documentation/knowledge-base/common-increase-signalr-max-message-size).

## PdfViewer Parameters

The table below lists the PDF Viewer parameters. Also check the [PDF Viewer API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikpdfviewer) for all parameters, methods and events.

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Parameter               | Type and Default Value                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ----------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AnnotationMode`        | `PdfViewerAnnotationMode` <br /> (`Disable`) | Specifies how the PDFViewer handles [form fields](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/form-filling) in the loaded document.                                                                                                                                                                                                                                                                                |
| `Class`                 | `string`                                     | An additional CSS class for the `<div class="k-pdf-viewer">` element. Use it to [customize the component styles and override the theme](https://www.telerik.com/blazor-ui/documentation/styling-and-themes/override-theme-styles).                                                                                                                                                                                                          |
| `Data`                  | `byte[]`                                     | The source of the currently displayed PDF file.                                                                                                                                                                                                                                                                                                                                                                                             |
| `EnableLoaderContainer` | `bool` <br /> (`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](https://www.telerik.com/blazor-ui/documentation/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` <br /> (`4m`)                      | The largest possible zoom level. The default value allows zooming in 4 times (400%).                                                                                                                                                                                                                                                                                                                                                        |
| `MinZoom`               | `decimal` <br /> (`0.5m`)                    | The smallest possible zoom level. The default value allows zooming out to 50%.                                                                                                                                                                                                                                                                                                                                                              |
| `RenderScale`           | `double` <br /> (`3.0`)                      | The resolution of the rendered PDF document. A higher value increases the quality, but also increases the memory consumption. Use a smaller value for large documents or less powerful user devices like mobile phones.                                                                                                                                                                                                                     |
| `Width`                 | `string`                                     | The PdfViewer width as a [CSS length value](https://www.telerik.com/blazor-ui/documentation/common-features/dimensions). If not set, the component will expand horizontally to fill its parent.                                                                                                                                                                                                                                             |
| `Zoom`                  | `object` <br /> (`1.25m`)                    | The current zoom level. Accepts a `decimal` ratio (e.g., `1.0m` for 100%, `1.5m` for 150%) or a `PdfViewerZoomLevelType` enum value (`ActualWidth`, `FitToWidth`, or `FitToPage`) for semantic zoom levels. Numeric values are clamped to \[`MinZoom`, `MaxZoom`]. Use the parameter with two-way binding or with a [`ZoomChanged` event handler](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/events#zoomchanged). |
| `ZoomRate`              | `decimal` <br /> (`0.25m`)                   | The zoom level change that is used by the zoom in and zoom out buttons.                                                                                                                                                                                                                                                                                                                                                                     |

## 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.

| Method         | Description                                                                                                                                                                                                                                                                    |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Print`        | Prints the loaded PDF document as an alternative to the [built-in Print button in the PDF Viewer toolbar](https://www.telerik.com/blazor-ui/documentation/components/pdfviewer/toolbar#built-in-tools).                                                                        |
| `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](https://www.telerik.com/blazor-ui/documentation/common-features/data-binding/overview#refresh-data). |
| `GetFileAsync` | Asynchronously retrieves the current PDF file data as a byte array, including any annotations or form filling changes. Returns a `Task<byte[]>`. Returns `null` if no document is loaded.                                                                                      |

> caption PDF Viewer reference and method usage

<demo metaUrl="client/pdfviewer/reference-methods/" height="550"></demo>

## Next Steps

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

## See Also

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