简体   繁体   中英

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:

Process.Start(_pathToPDFFile);

This works with Adobe Acrobat, but not with Adobe Reader. When Adobe Reader is installed, Process.Start() does nothing unless the Reader process is already running in the Task Manager.

How can I get Adobe Reader to show the PDF when I attempt to start a PDF?

In our case, the problem was only reproducible when starting the application from Visual Studio - starting the .exe directly works as expected.

After some debugging, it turned out that Visual Studio was set to always run as administrator, which causes the issue. 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 :

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.

Maybe try something like this? I tried you code on Windows 8 with Adobe Reader 11 and it seems to work fine for me. 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. 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.

If Adobe Reader is not the default PDF program, you need must get path to AcroRd32.exe. This post should help you. Then just execute code in Hybris95's answer.

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

I still have this problem, can't make the AcroRd32.exe to open, just stays there in the task manager. A possible solution is choosing chrome.exe to start the PDF.

Like this:

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

p.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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