How to open pdf file in Windows Phone 8?
I have some pdf files inside (the project files) my app and I wanted how to open in Adobe Reader or the other, but I don't know how.
In iOS is more easy and in Android I know how, but I don't know how in WP8.
I'm new in Windows Phone 8 :/
Thanks for all!
You have to use the LaunchFileAsync
method of Launcher
class. Example:
// Access the file.
StorageFile pdfFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");
// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdfFile);
You will find more info here:
Auto-launching apps using file and URI associations for Windows Phone 8
Save the downloaded file to the isolated storage...
async void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
byte[] buffer = new byte[e.Result.Length];
await e.Result.ReadAsync(buffer, 0, buffer.Length);
using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = storageFile.OpenFile("your-file.pdf", FileMode.Create))
{
await stream.WriteAsync(buffer, 0, buffer.Length);
}
}
}
Open and display the pdf file from the isolated storage..
// Access the file.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile pdffile = await local.GetFileAsync("your-file.pdf");
// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdffile);