Get started with Blazor
The full viewer as a Razor component. You write no JavaScript.
Install
dotnet add package DocuVerseOne package: the engine for .NET, and on .NET 10 ASP.NET Core the Blazor component (Blazor Server or a Blazor Web App with interactive server rendering).
A licence key is needed: without one, nothing opens. Make a free account for trial keys (everything works, with a watermark), or choose a plan on the pricing page. Each key is for one SDK, made in your account under Keys: a Web SDK key for the viewer in websites (
licenseKey), a Server SDK key for Node.js (setLicenseKey(key)) and .NET (License.SetKey(key)), a Mobile SDK key for apps. A key used with another SDK is refused with an error that says which key to make.Add the component
@using DocuVerse.Blazor@rendermode InteractiveServer <PdfViewer @ref="viewer" Document="@bytes" Author="Jane Doe" HeaderButtons="@buttons" OnHeaderButton="OnButton" OnSave="Saved" /> @code { PdfViewer? viewer; byte[] bytes = File.ReadAllBytes("contract.pdf"); PdfHeaderButton[] buttons = { new("approve", "Approve") }; async Task OnButton(string id) => await File.WriteAllBytesAsync("approved.pdf", await viewer!.SaveAsync()); Task Saved(PdfSavedEventArgs e) => File.WriteAllBytesAsync(e.FileName, e.Bytes);}Parameters
| Parameter | Meaning |
|---|---|
Document, DocumentUrl, FileName | PDF, Word or Excel file to open (bytes or URL); none shows an Open button |
Author, Theme, AccentColor, ReadOnly | Look and behaviour; Theme is light, dark or auto |
Tools, DisabledElements, InitialZoom, InitialTab, Height | Which tools and parts show, starting zoom and tab, height (default 100vh) |
Layout, ScrollMode | Page layout (single, double or cover) and scrolling (continuous or page) |
HeaderButtons + OnHeaderButton | Your own header buttons, handled in C# |
OnSave | Receive the saved bytes in C# instead of downloading |
OnEvent, OnReady | Viewer events such as documentLoaded and annotationsChanged |
Methods: SaveAsync(incremental), SaveWordAsync(), LoadAsync(bytes, fileName), LoadUrlAsync(url), SetToolAsync(tool), SetThemeAsync(theme), AnnotationsJsonAsync(), IsWordDocumentAsync().