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 information about opening PDFs from the following locations:
- Opening a PDF from a URL
- Opening a PDF from the cloud
- Opening a PDF from the database
- Opening a PDF from the file system
Conclusion
We hope you enjoyed learning about how to display PDFs from byte arrays using the Blazor PDF Viewer. You can explore the runnable sample of displaying PDFs from byte arrays using the Blazor PDF Viewer from this GitHub location.
If you have any questions or require clarifications, please let us know in the comments below. You can also contact us through our support forums.