Nutrient Web SDK is a JavaScript PDF library for viewing, annotating, and editing PDFs directly in the browser. Use it to add PDF capabilities to any web app.
This guide walks you through the steps to integrate Nutrient Web SDK into your project. By the end, you'll be able to render a PDF document in the UI.
Installation
Nutrient Viewer library files are distributed as an archive that you extract manually:
Download the framework here. The download will start immediately and will save a
.tar.gz
archive likePSPDFKit-Web-binary-1.0.0.tar.gz
to your computer.Once the download is complete, extract the archive and copy the entire contents of its
dist
folder to thewwwroot
directory in your project.Make sure your
wwwroot
folder contains the filenutrient-viewer.js
and anutrient-viewer-lib
directory with library assets.
Render a PDF
These steps cover both Server and WebAssembly.
Rename the PDF document you want to display in your application to
document.pdf
, and place it in thewwwroot
directory. You can use this demo document as an example.To clean out the UI, go to the
Shared/MainLayout.razor
component and keep only the@Body
property:@inherits LayoutComponentBase@BodyGo to the Home route located under the
Pages/Index.razor
file, and replace the contents of the file with the following:@page "/"@inject IJSRuntime JS<div id='container' style='background: gray; width: 100vw; height: 100vh; margin: 0 auto;'></div>@code {protected override async void OnAfterRender(bool firstRender){if (firstRender) {await JS.InvokeVoidAsync("loadPDF", "#container", "document.pdf");}}}Load Nutrient Viewer into
Pages/_Host.cshtml
before the</body>
tag:@* Include nutrient-viewer.js in your Pages/_Host.cshtml file *@<script src="dist/nutrient-viewer.js"></script>@* Initialize Nutrient Viewer in Blazor Server by calling NutrientViewer.load(): *@<script>function loadPDF(container, document) {NutrientViewer.load({container: container,document: document})}</script>Server only: make sure to add the MIME type mappings to allow conversion of Office files:
- Go to
Program.cs
. - Import
using Microsoft.AspNetCore.StaticFiles;
. - Add the following code to your app builder:FileExtensionContentTypeProvider extensionProvider = new();extensionProvider.Mappings.Add(".dll", "application/octet-stream");extensionProvider.Mappings.Add(".dat", "application/octet-stream");extensionProvider.Mappings.Add(".blat", "application/octet-stream");app.UseStaticFiles(new StaticFileOptions{ContentTypeProvider = extensionProvider});
- Go to
Run the app.
Server: start the app in the root directory of your project:
sh dotnet watch run
WebAssembly: select Run > Start Debugging. This will start your app and open it in your default browser.