PDF无法在WP8设备上打开

时间:2014-03-26 10:21:14

标签: c# silverlight pdf windows-phone-8 windows-phone

我的文件夹中有一些pdf,比如Data / PDF / abc.pdf。

我正在尝试使用以下代码打开PDF:

private async void LaunchPDFNew(string name)
        {
            string imageFile = @"Data/PDF/"+name+".pdf";

            // Get the image file from the package's image directory
            var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
            if (file != null)
            {
                bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
                if (success)
                {
                    // File launched
                    Debug.WriteLine("File Launched");
                }
                else
                {
                    // File launch failed
                    Debug.WriteLine("File Launched Failed");
                }
            }
            else
            {
                // Could not find file
                Debug.WriteLine("Could not find the file");
            }
        }

它给了我错误:

A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary

我已尝试使用以下链接中给出的解决方案

Launching PDF reader on windows phone 8

但他们都没有工作。如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

对于那些无法打开PDF的人。

1)确定一个名为" abc.pdf"的文件。在项目中,将Build Action设置为Content,将Copy to Output Directory设置为Copy for newer)

2)如果pdf文件在目录中,则使用\而不是/,所以

string file = @"Data/PDF/"+name+".pdf";

应该是

string file = @"Data\PDF\"+name+".pdf";

3)最后使用这个:

private async void LaunchPDF(string name)
        {
            string file = @"Data\PDF\"+name+".pdf";

            // Get the image file from the package's image directory
            var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
            if (file != null)
            {
                bool success = await Windows.System.Launcher.LaunchFileAsync(file);
                if (success)
                {
                    // File launched
                    Debug.WriteLine("File Launched");
                }
                else
                {
                    // File launch failed
                    Debug.WriteLine("File Launched Failed");
                }
            }
            else
            {
                // Could not find file
                Debug.WriteLine("Could not find the file");
            }
        }