How to open pdf file in Windows Phone 8?

后端 未结 3 1430
再見小時候
再見小時候 2020-12-01 20:09

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 And

相关标签:
3条回答
  • 2020-12-01 20:31

    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

    0 讨论(0)
  • 2020-12-01 20:43

    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);
    
    0 讨论(0)
  • 2020-12-01 20:47
    async void launchPDF()
    {
     string fileURL = @"Assets\file.pdf";
     StorageFile pdfFile = await 
     Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileURL);
     if (pdfFile != null)
     {
       IAsyncOperation<bool> success = 
               Windows.System.Launcher.LaunchFileAsync(pdfFile);
    
       if (await success)
       {
         // File launched
       }
       else
       {
         // File launch failed
       }
     }
     else
     {
    
     }
    }
    

    Make sure pdf file build action is content

    0 讨论(0)
提交回复
热议问题