How to display PDFs from byte arrays using Blazor PDF Viewer
The Blazor PDF Viewer is a UI component for displaying PDFs from byte arrays, streams, or file paths. In addition to being able to print PDFs, it also supports reviewing PDFs with annotation tools. Thumbnails, bookmarks, hyperlinks, and tables of content provide easy navigation within and outside PDF files. The Form-filling support allows filling and printing with AcroForms.
Display PDF from byte arrays
In this Knowledge Base, you can find information about how to display PDF files from byte arrays. The following code sample explains how the PDF file can be loaded in the PDF Viewer as a base64 string.
Refer to the following code sample.
@using Syncfusion.Blazor.PdfViewerServer <SfPdfViewerServer ID="pdfviewer" DocumentPath="@DocumentPath" Width="1060px" Height="500px"/> @code { static byte[] byteArray = System.IO.File.ReadAllBytes("wwwroot/data/PDF_Succinctly.pdf"); static string base64String = Convert.ToBase64String(byteArray); public string DocumentPath { get; set; } = "data:application/pdf;base64," + base64String; }
You can refer to this link to learn about how to open PDF files from various locations. Also, please find the following locations.
- Opening a PDF from URL
- Opening a PDF from Cloud
- Opening a PDF from the database
- Opening a PDF from the file system
Conclusion
I hope you enjoyed learning about
how to display PDFs from byte arrays using Blazor PDF Viewer. You can explore
the runnable sample of display PDFs from byte arrays using the Blazor PDF
Viewer from this GitHub location.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums