First of all, WebView
is not a web control so you can't use it in the razor page inside the BlazorWebView
. And then the android webview doesn't support display local pdf, it supports Google PDF Viewer to display pdf online.
So you may need to use some other plugins to do that. Such as: Blazor PDF Viewer.
- Set up it step by step according to the official document:Getting started - MAUI Blazor Hybrid App (.NET 8).
- And then using the following code to display the PDF:
<p>@eventLog</p><PdfViewer Class="mb-3"Url="@string.Format("data:application/pdf;base64,{0}", pdfBase64String)"OnDocumentLoaded="OnDocumentLoaded"OnPageChanged="OnPageChanged" />@code { private string eventLog { get; set; } = $"Last event: ..., CurrentPage: 0, TotalPages: 0"; private string pdfBase64String; protected override void OnInitialized() { Byte[] bytes = File.ReadAllBytes("/data/user/0/com.companyname.mycomapny/files/WorkOrders/OrderOne/OrderOne.pdf"); // get pdf as base64 string pdfBase64String = Convert.ToBase64String(bytes); } private void OnDocumentLoaded(PdfViewerEventArgs args) => eventLog = $"Last event: OnDocumentLoaded, CurrentPage: {args.CurrentPage}, TotalPages: {args.TotalPages}"; private void OnPageChanged(PdfViewerEventArgs args) => eventLog = $"Last event: OnPageChanged, CurrentPage: {args.CurrentPage}, TotalPages: {args.TotalPages}";}