Hello,
Your pdfFilePath cannot be accessed. Here are my steps to make webview to show the pdf.
Firstly, I create a pdfjs folder in the Resources/Raw/
, then copy build
and web
content from pdfjs to the Resources/Raw/pdfjs
, and I copy the UserGuide.pdf file to the Resources/Raw/
, please make sure your build action of UserGuide.pdf is MauiAsset
.
Next, add following handler to enable javascript and access files for webview like following code.
Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if ANDROID
handler.PlatformView.Settings.JavaScriptEnabled=true;
handler.PlatformView.Settings.AllowFileAccess = true;
handler.PlatformView.Settings.AllowFileAccessFromFileURLs = true;
handler.PlatformView.Settings.AllowUniversalAccessFromFileURLs = true;
#elif IOS
#endif
});
Here is my string pdfFilePath = $"file:///android_asset/pdfjs/web/viewer.html?file=file:///android_asset/UserGuide.pdf"; ;
.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.