简体   繁体   English

Process.Start(/ * pdf * /的路径)不适用于Windows 8上的Adobe Reader

[英]Process.Start(/* path to pdf */) doesn't work with Adobe Reader on Windows 8

I'm able to create PDFs in my C#/WPF application and run them with the following: 我能够在我的C#/ WPF应用程序中创建PDF并使用以下命令运行它们:

Process.Start(_pathToPDFFile);

This works with Adobe Acrobat, but not with Adobe Reader. 这适用于Adobe Acrobat,但不适用于Adobe Reader。 When Adobe Reader is installed, Process.Start() does nothing unless the Reader process is already running in the Task Manager. 安装Adobe Reader时,除非Reader进程已在任务管理器中运行,否则Process.Start()不会执行任何操作。

How can I get Adobe Reader to show the PDF when I attempt to start a PDF? 当我尝试启动PDF时,如何让Adobe Reader显示PDF?

In our case, the problem was only reproducible when starting the application from Visual Studio - starting the .exe directly works as expected. 在我们的例子中,问题只能从Visual Studio启动应用程序时重现 - 启动.exe直接按预期工作。

After some debugging, it turned out that Visual Studio was set to always run as administrator, which causes the issue. 经过一些调试后,发现Visual Studio设置为始终以管理员身份运行,这会导致问题。 Turning this off ( which is hard enough itself ) fixes the problem. 关闭它( 这本身很难 )解决了这个问题。

Still not sure why this happens, though. 但仍然不确定为什么会这样。

Here is how I do, there may be a way to recover the exact path to AcroRd32.exe from Registry although : 我是这样做的,可能有一种方法可以从Registry中恢复到AcroRd32.exe的确切路径,尽管:

String pathToAcroRd32 = Environment.GetEnvironmentVariable("ProgramFiles") + ((Environment.Is64BitOperatingSystem) ? @" (x86)\" : @"\") + "Adobe\Reader 11.0\Reader\AcroRd32.exe";
ProcessStartInfo adobeInfo = new ProcessStartInfo(pathToAcroRd32, _pathToPDFFile);
Process.Start(adobeInfo);

Depending also on the version of Acrobat Reader to launch (if different from Adobe Reader 11.0) you may have to change the path. 还要根据要启动的Acrobat Reader版本(如果与Adobe Reader 11.0不同),您可能需要更改路径。

Maybe try something like this? 也许尝试这样的事情? I tried you code on Windows 8 with Adobe Reader 11 and it seems to work fine for me. 我尝试使用Adobe Reader 11在Windows 8上编写代码,它似乎对我来说很好。 Maybe something else is wrong on the machine in question? 也许有问题的机器还有其他问题?

var process = new Process();
process.StartInfo = new ProcessStartInfo(@"Path to your PDF.pdf");
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = true;
process.Start();

First, you must check if Adobe Reader is the default program for pdf files. 首先,您必须检查Adobe Reader是否是pdf文件的默认程序。 You can check it in Control Panel -> Programs -> Default Programs -> Set Associations. 您可以在控制面板 - >程序 - >默认程序 - >设置关联中进行检查。

If Adobe Reader is the default PDF program, your code should work on Windows 8, actually in most version of Windows. 如果Adobe Reader是默认的PDF程序,则您的代码应该适用于Windows 8,实际上在大多数Windows版本中。

If Adobe Reader is not the default PDF program, you need must get path to AcroRd32.exe. 如果Adobe Reader不是默认的PDF程序,则必须获取AcroRd32.exe的路径。 This post should help you. 这篇文章应该对你有帮助。 Then just execute code in Hybris95's answer. 然后在Hybris95的答案中执行代码。

我没有看到您的完整代码,但我通过将ProcessStartInfo.UseShellExecute设置为true来解决类似的问题。

I still have this problem, can't make the AcroRd32.exe to open, just stays there in the task manager. 我仍然有这个问题,无法打开AcroRd32.exe,只是在任务管理器中停留。 A possible solution is choosing chrome.exe to start the PDF. 一种可能的解决方案是选择chrome.exe来启动PDF。

Like this: 像这样:

var p = new Process
{
    StartInfo = new ProcessStartInfo(@"chrome.exe",  path)
    {
        WindowStyle = ProcessWindowStyle.Maximized
    }
};

p.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM