【发布时间】:2025-12-24 19:35:12
【问题描述】:
所以我有代码以编程方式打开 pdf。代码可以很好地打开 adobe reader,但我会弹出一个对话框,提示该文件不存在。问题是我可以浏览到用于尝试在 Windows 浏览器中打开 pdf 的确切路径,此外还有一个 if 语句来判断文件是否存在。那么为什么adobe不打开pdf呢?
proc.StartInfo.FileName 上的 Adobe .exe 路径正确。
我找到了这个链接:https://visibleprocrastinations.wordpress.com/2009/08/20/there-was-an-error-opening-this-document-file-cannot-be-found-acrobat-reader/,但我不知道它是否仍然适用
PDF文件路径:
C:\Users\Printer\SharePoint\Partners - Doc\McG\Labels\TR109897\eLabels_TR109897.pdf
这是我正在使用的代码:
Process proc = new Process();
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
//Define Location of adobe reader/command line
proc.StartInfo.FileName = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Arguments = string.Format(@"{0}", file.FullName);
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
if (proc.HasExited == false)
proc.WaitForExit(10000);
proc.Close();
return true;
}
【问题讨论】:
-
首先,Process 只在本地机器上工作。如果您在 Web 应用程序中拥有它,那么该过程将发生在服务器上,而不是用户的 PC 上。考虑将“临时”pdf文件保存到用户临时文件夹并从那里打开它。您将不得不研究流媒体。
-
它在本地机器上。
-
不是 WPF 特定的,删除了标签。