2012-10-29 43 views
1

如何阅读Windows 8应用程序中的pdf文件。在我的Windows 8应用程序中如何打开PDF文件。如何在Windows 8应用程序中使用c#打开pdf文件?

在清单文件中,我写了下面的代码。

<Extensions> 
     <Extension Category="windows.fileTypeAssociation"> 
      <FileTypeAssociation Name="pdf"> 
      <SupportedFileTypes> 
       <FileType>.pdf</FileType> 
      </SupportedFileTypes> 
      </FileTypeAssociation> 
     </Extension> 
     </Extensions> 

和后面的代码。

string imageFile = @"Images\DX730_EN.pdf"; 

      var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile); 

      if (file != null) 
      { 
       // Set the option to show the picker 
       var options = new Windows.System.LauncherOptions(); 
       options.DisplayApplicationPicker = true; 

       // Launch the retrieved file 
       bool success = await Windows.System.Launcher.LaunchFileAsync(file, options); 
       if (success) 
       { 
        // File launched 
       } 
       else 
       { 
        // File launch failed 
       } 
      } 
      else 
      { 
       // Could not find file 
      } 

我无法打开PDF文件。请告诉我错误在哪里?

回答

0
+0

代码如何打开pdf文件? – user1727822

+0

哪种语言? –

+0

在Windows 8应用程序中,我需要打开PDF文件使用C#。请让我知道。 – user1727822

0

解决的办法是,你可以打开Windows.ApplicationModel.Package.Current.InstalledLocation PDF文件...

所以,穿上本地文件夹的PDF并从中打开。

StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; 
    StorageFile file= await localFolder.GetFileAsync("myFile.pdf"); 
    if (file != null) 
       { 
        // Set the option to show the picker 
        var options = new Windows.System.LauncherOptions(); 
        options.DisplayApplicationPicker = true; 

        // Launch the retrieved file 
        bool success = await Windows.System.Launcher.LaunchFileAsync(file, options); 
       } 
+0

这工作正常。你能建议如何使用启动器打开pdf的特定页面吗? – Nitika

相关问题