I plan to display a PDF file on my MAUI app. I tried following the answer at this link (https://learn.microsoft.com/en-us/answers/questions/1310387/how-to-view-the-pdf-file-from-maui) and it worked for Android.
The PDF is in the Resources\Raw.
I want to display it also in iOS and Windows.
How can we pass the PDF file for these OSs?
I tried, but it doesn't work. Here my attempt.
using System;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
public partial class PdfPage : ContentPage
{
public PdfPage()
{
InitializeComponent();
LoadPdfViewer();
}
private void LoadPdfViewer()
{
#if ANDROID
pdfFilePath = $"file:///android_asset/pdfjs/web/viewer.html?file=file:///android_asset/simple.pdf";
#elif WINDOWS
pdfFilePath = $"pdfjs/web/viewer.html?file=ms-appx-web:///simple.pdf";
#elif IOS
pdfFilePath = $"pdfjs/web/viewer.html?file=file:///simple.pdf";
#endif
PdfWebView.Source = new UrlWebViewSource { Url = pdfFilePath };
}
}
In the post linked above there is also specified the following:
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
#elif WINDOWS
#endif
});
How can we apply this code also for iOS and Windows?
Thanks.