How to open pdf files in windows 8 application using c#?

北慕城南 提交于 2019-12-08 08:20:53

问题


How to read the pdf files in windows 8 app .In my windows 8 application how to open the pdf files .

In manifest file i wrote the below code.

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

and code behind.

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
            }

i could not able to open the pdf file.please tell me where is error?


回答1:


you can use the LaunchFileAsync method of the Windows.System.Launcher class.

Take a look at this: http://msdn.microsoft.com/en-us/library/windows/apps/hh701465.aspx




回答2:


Windows 8 comes with windows Reader to read pdf files .

This link might help you

http://www.howto-connect.com/how-to-view-pdf-file-in-windows-8-what-is-windows-reader/

If that doesn't help, this might

http://social.technet.microsoft.com/Forums/en-US/W8ITProPreRel/thread/b19fc6d8-531f-4cf2-8d6d-f1dc9e93a93d/




回答3:


The solution is, you can open pdf files on Windows.ApplicationModel.Package.Current.InstalledLocation...

So, put the pdf on local folder and open from it.

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


来源:https://stackoverflow.com/questions/13118338/how-to-open-pdf-files-in-windows-8-application-using-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!