Hi,
I'm trying to display a PDF saved in local on my iOS App.
Here's my code, it works with a Web URL (example : http://xamarin.com
) but not with a local url (example : /Users/username/Library/Developer/CoreSimulator/Devices/5FRA9CFD-CEVC-445D-B9C4-3D6708A469V2/data/Containers/Data/Application/9E851B1A-9DA3-43CE-9103-1DE7ED86E434/Documents/myFile.pdf
).
Here's my C# code :
public class WebViewDoc : ContentPage { public WebViewDoc (String filename) { String documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); String fullPath = Path.Combine (documentsPath, filename); // Result : /Users/username/Library/Developer/CoreSimulator/Devices/5FRA9CFD-CEVC-445D-B9C4-3D6708A469V2/data/Containers/Data/Application/9E851B1A-9DA3-43CE-9103-1DE7ED86E434/Documents/myFile.pdf var browser = new WebView (); browser.Source = @fullPath; // Works if replacing by a web url Content = browser; } }
Did someone have a solution ?
Thank you,
Simon
Posts
have you tried using a "file://" scheme with the url?
Hi @JasonAwbrey ,
Yes, and still not ok.
Here's the code to save the file on my app, maybe the problems come from it?
@SimonDellise , @JasonAwbrey
I am currently having the same issue. There are plenty of example for Android but not for iOS. I tried using
file://
without success. I am wondering if it is a simulator issue or something else...Hi @hvaughan , I've used this for iOS :
The problem was simply the spaces in the file name ... So I replaced all of them by an underscore ( _ ) and now, it works fine !
The webview code :
I hope this will help you.
@SimonDellise
Awesome! Thank you. I think that solved it for me. I also was not using
.ApplicationData
.One more question if you don't mind, for Android, when you open using another application (such as adobe reader), are you handling the case when the user does not have any PDF viewer installed? I found
PDF.js
(link below), but just wanted to see if you had a better alternative. Thanks again.http://subodhjena.com/xamarin-displaying-pdf-files-on-android-webview/
@hvaughan You're welcome
Unfortunately, I haven't found any better solution at your question. I think PDF.js is a great alternative to the native app.