2012-10-29 40 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

相關問題