blazor-405847-components-pdf-viewer-get-started-with-pdf-viewer.md
This topic describes how to create a new project or configure an existing project to use a DevExpress Blazor PDF Viewer component.
Follow this tutorial to create a Blazor application using the DevExpress Template Kit. To add a PDF Viewer to the application, choose the corresponding option in the Kit.
Follow the steps below to incorporate a PDF Viewer into an existing Blazor app.
Create an application as described in the following topic: Get Started With DevExpress Components for Blazor.
Install the DevExpress.Blazor.PdfViewer NuGet package.
Register the DevExpress.Blazor.PdfViewer namespace in the _Imports.razor file:
Register the DevExpress.Blazor.Reporting.Models namespace to access and modify toolbar settings.
Register the PDF Viewer-related services in the Program.cs file:
Register the PDF Viewer’s CSS file:
To use the DevExpress Blazor PDF Viewer in WebAssembly and .NET MAUI Blazor Hybrid applications, complete the following steps:
For non-Windows environments ( Linux , macOS , and Azure/AWS cloud platforms), install the DevExpress.Pdf.SkiaRenderer NuGet package. For additional information, refer to Use Reporting on Linux and macOS.
On Linux , you must also install the following font libraries:
sudo apt-get install -y libc6 libicu-dev libfontconfig1
sudo apt-get install -y libc6 libicu-dev libfontconfig1
sudo yum install -y glibc-devel libicu fontconfig
sudo zypper install -y libicu fontconfig
sudo apk add icu-libs icu-data-full fontconfig
For applications on Windows Azure , set the PdfPrintingOptions.RenderingEngine property to Skia (see XRPdfContent Control Specifics).
Follow the steps below to add a PDF Viewer Component:
.razor file: <DxPdfViewer>…</DxPdfViewer>.<DxPdfViewer DocumentContent="DocumentContent"
ZoomLevel="1" />
@code {
byte[]? DocumentContent { get; set; }
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
await using Stream stream =
System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream("PDFViewerServer.Documents.Invoice.pdf")
?? throw new InvalidOperationException("Resource not found.");
using MemoryStream ms = new();
await stream.CopyToAsync(ms);
DocumentContent = ms.ToArray();
}
}