1

I use the Xamarin.Forms 4.6.0.800

I view a PDF file on Android using the following code in the constructor of my ContentPage.

 // Get access to the local file system var localFileService = DependencyService.Get<ILocalFileService>(); // Save the PDF to a temporary file var temporaryFile = localFileService.SaveToTempPDFFile(reportName, pdfData); // Set the WebView to reference the temporary PDF file PdfView.Source = $"file:///android_asset/pdfjs/web/viewer.html?file={temporaryFile}"; 

The XAML is simply:

<ContentPage.Content> <WebView x:Name="PdfView" VerticalOptions="Fill" HorizontalOptions="Fill" /> </ContentPage.Content> 

This has been working for quite a while, but today on re-testing, I get the following error:

file:///Android_asset/pdfjs/web/viewer.html?file=/data/user/0/com.myApp/cache/reportname.pdf could not be loaded because: net::ERR_FILE_NOT_FOUND 

Has something changed in Xamarin recently to cause this? In the meantime I am searching for something I may have changed that could be causing this error (as it has been working fine for quite a while now).

2 Answers 2

1

I found what was causing it, but no idea why. In the Android project, I had set the Platform Target to x64. Changed it back to Any CPU and it all works again???

It has reappeared again, but only when I install it on a Pixel 4 (my test phone). Emulators are OK.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting the same error when trying to load a pdf on my Galaxy S8. I'm also using pdfjs, and my code is very similar to yours. Like you, my code works in the emulator, and my code has been working fine until I tested today.
0

I got it to work by just rebuilding the project, archiving, and testing the APK from the App Store.

I noticed the APK file size was smaller when the ERR_FILE_NOT_FOUND error would happen. The good APK is closer in file size to my last good APK (from January 2020). Just a guess, maybe an optimization during the archive process is causing this?

I could only verify that PDFs are displaying with an installation from the App Store. PDFs display fine when testing in the emulator, and with direct-to-phone builds.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.