【问题标题】:How to open pdf file in Windows Phone 8?如何在 Windows Phone 8 中打开 pdf 文件?
【发布时间】:2013-07-11 00:44:38
【问题描述】:

我的应用程序中有一些 pdf 文件(项目文件),我想如何在 Adob​​e Reader 或其他软件中打开,但我不知道如何。

在 iOS 中更容易,在 Android 中我知道如何,但我不知道在 WP8 中如何。

我是 Windows Phone 8 的新手:/

谢谢大家!

【问题讨论】:

    标签: pdf windows-phone-8


    【解决方案1】:

    您必须使用Launcher 类的LaunchFileAsync 方法。示例:

    // Access the file.
    StorageFile pdfFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");
    
    // Launch the pdf file.
    Windows.System.Launcher.LaunchFileAsync(pdfFile);
    

    您将在此处找到更多信息:

    Auto-launching apps using file and URI associations for Windows Phone 8

    【讨论】:

    • 使用此代码,应用程序会显示此错误:线程 0xf68 已退出,代码为 259 (0x103)。 “TaskHost.exe”(CLR C:\windows\system32\coreclr.dll:Silverlight AppDomain):已加载“C:\windows\system32\System.Runtime.ni.dll”。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 “TaskHost.exe”(CLR C:\windows\system32\coreclr.dll:Silverlight AppDomain):已加载“C:\windows\system32\en-US\mscorlib.debug.resources.dll”。模块是在没有符号的情况下构建的。 mscorlib.ni.dll 中发生了“System.IO.FileNotFoundException”类型的第一次机会异常
    • file.pdf 与 App.xml 处于同一级别
    • 但是,我的文件路径是什么?
    • 我明白了,错误:“值不在预期范围内。”
    • 要执行“StorageFile pdfFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");”,尝试捕获一个异常,显示“值不属于预期范围”
    【解决方案2】:
    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
     {
    
     }
    }
    

    确保 pdf 文件构建操作是内容

    【讨论】:

      【解决方案3】:

      将下载的文件保存到隔离存储...

      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);
              }
          }
      }
      

      打开并显示隔离存储中的 pdf 文件..

      // 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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多