This guide shows how to build a Blazor PDF viewer using the Apryse WebViewer SDK. You'll learn how to integrate the SDK into a Blazor application to render, view, and interact with PDF documents using the WebViewer UI.
You can also download ready-to-go GitHub samples for Blazor server and Blazor wasm to get started quickly. Additionally, explore the interactive Showcase demo to see WebViewer's full capabilities in action.
This guide assumes basic familiarity with Blazor development. Before you start:
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
In this section, you’ll create a new Blazor application using the .NET CLI. This project provides the foundation for integrating Apryse WebViewer. If you already have a Blazor app, skip this and continue to Install WebViewer.
If this prints a version number, you're ready to proceed. If not, install the .NET SDK and rerun the command.
2. In your terminal, go to the directory where you want to create the project.
3. Create a new webviewer-blazor project:
4. Navigate to your new Blazor project directory, initialize your project, and generate a package.json file:
Flags are used to skip prompts during project configuration. The setup creates a package.json file with all default values. Select different options if preferred.
The final package.json should look like this:
Next, install the Apryse WebViewer SDK using npm. This command adds the WebViewer package to your project, allowing you to integrate the PDF viewer and editor into your Blazor application.
After navigating to your webviewer-blazor project directory, run the following command to install WebViewer:
WebViewer needs access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. In a Blazor project, you must copy these assets into the public directory so they can be served correctly. For more, see Copying WebViewer static assets.
wwwroot/lib/webviewer/public directory if it doesn't already exist:2. Copy all WebViewer static assets from node_modules/@pdftron/webviewer/public into the new wwwroot/lib/webviewer/public directory:
3. Copy the webviewer.min.js library file from node_modules to the public directory:
Your project should now include a similar structure:
In this section, you’ll add WebViewer to your Blazor app by loading the WebViewer script and creating a Razor component that initializes the viewer and renders it in the UI, where it loads and displays a document.
Components/App.razor file with the following and save:Components/App.razor
2. Create a new Components/WebViewer.razor file, add the following code, and save:
Components/WebViewer.razor
3. Replace the Components/Pages/Home.razor file with the following and save:
Components/Pages/Home.razor
You can now load and display a PDF document in the WebViewer UI. Run your Blazor application to launch WebViewer and see the PDF in your browser.
A successful output looks similar to:
2. Open the localhost URL from your terminal to view the WebViewer UI and PDF document.
WebViewer fails to load due to MIME type issues
If WebViewer doesn't load or you see a blank or partially rendered UI, the server may not be serving certain file types correctly. WebViewer includes files with .wasm, .gz, and .br extensions, which require proper MIME types that aren't always configured by default in Blazor.
To fix this, configure the application to serve these file types by updating Program.cs:
Program.cs
Restart the application after making these changes.
In this 5-minute video, learn how to install and integrate the Apryse WebViewer SDK into a Blazor project.
Integrate the WebViewer SDK into an ASP.NET Core–hosted Blazor project.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales