Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 299
Oscar Fernandez Avatar asked Jul 12 '13 13:07

Oscar Fernandez


2 Answers

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

like image 142
anderZubi Avatar answered Nov 15 '22 12:11

anderZubi


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);
like image 39
senimii Avatar answered Nov 15 '22 10:11

senimii