Frameworks
Integrations
Mendix
SharePoint
Modular UI
Legacy UI
AnnotationManager
Annotation Types
Customize
Version 11
Version 10
v10.12
v10.11
v10.10
v10.9
v10.8
v10.7
v10.6
v10.5
v10.4
v10.3
v10.2
v10.1
v10.0
Version 8
v8.12
v8.11
v8.10
v8.9
v8.8
v8.7
v8.6
v8.5
v8.4
v8.3
v8.2
v8.1
v8.0
Version 7
Version 6
v6.3
v6.2
v6.1
v6.0
Version 5
Version 4
Version 3
Version 2
WebViewer Server
WebViewer BIM
This guide will show you how to integrate WebViewer Document Viewer & Editor into a Blazor application.
You can also download a ready-to-go sample on GitHub for Blazor server sample or for Blazor wasm sample.
Prior to starting, you should have already installed Node and npm.
Clone the Blazor server sample by executing
Once cloned, navigate into the webviewer-blazor-sample
or webviewer-blazor-wasm-sample
directory and install all the required dependencies by executing
npm will also download the Apryse WebViewer and extract it to /wwwroot/lib
.
To run the sample, navigate to your webviewer-blazor-sample/
or webviewer-blazor-wasm-sample
directory and execute
Then navigate to https://localhost:5001/webviewer
or http://localhost:5000/
. You should see the application load on your browser.
To call more WebViewer API's, navigate to /wwwroot/js/webviewerScripts.js
and add the API calls in the callback of the WebViewer constructor(you may need to make one if it is not provided). Add your own license key in place of 'YOUR_LICENSE_KEY'.
For example, you can add instance.setTheme('dark')
to change the WebViewer UI theme to dark. If you stop the server, and execute dotnet run
again, then reload the page, you should see the theme change:
MIME issues
Enable MIME type mappings for WebViewer to load documents.
Server-side document operations with .NET Core SDK
Handle document operations through the JavaScript interop by passing its base64 data.
This guide will show you how to integrate WebViewer Document Viewer & Editor into a Blazor application.
If you are using the client-side model of Blazor, please make sure the server hosting the static files includes the MIME type mappings outlined here.
Navigate to your Blazor project. Let's call the path to your project PROJ_ROOT
:
From the WebViewer.zip
file you downloaded, copy the lib
folder into the static folder of your application, which is usually wwwroot
.
First to ensure Blazor can use the WebViewer library and APIs, open the main HTML file of your project(should be either PROJ_ROOT/wwwroot/index.html
or PROJ_ROOT/Pages/_Host.cshtml
). Add the WebViewer library as a script tag in the <head>
element of that file:
Next to call WebViewer APIs, we need to wrap them in a JavaScript object. Make a js
folder in your static directory if it does not exist already, and make a new file in it called webviewerScripts.js
. Add your own license key in place of 'YOUR_LICENSE_KEY'.
Inside that file, we define a new object called webviewerFunctions
and expose that to window
:
Then to make sure Blazor can find this file, again add a script tag to the main html file of your project, but this time inside the <body>
element:
Now that we have wrapped the WebViewer JavaScript instantiation function, we need to define the actual page for WebViewer to run in. Make a new page under PROJ_ROOT/Pages
and call it WebViewer.razor
.
Inside this page make a div element called viewer
for the instantiation to attach to:
Then override the OnAfterRender()
method of the page and invoke the initWebViewer
function we defined earlier:
Your final WebViewer.razor
file should look something like this:
Add the required WebViewer MIME type formats by adding a provider to startup.cs
:
Your final startup.cs
should look something like this:
You can test that the WebViewer is now part of your application by running the following:
In your browser, go to https://localhost:5001/webviewer
to see the WebViewer in action.
MIME issues
Enable MIME type mappings for WebViewer to load documents.
Server-side document operations with .NET Core SDK
Handle document operations through the JavaScript interop by passing its base64 data.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales