使用C#代码在Adobe Reader 11中打开特定页面的PDF文件失败。

4
以下代码用于在C#中打开PDF文件的特定页面。该代码对所有Adobe版本(除了最新版本11)都有效。
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "AcroRd32.exe";
myProcess.StartInfo.Arguments = "/A \"page=2=OpenActions\" C:\\Jack and Jill.pdf";
myProcess.Start();

请问adobe reader 11有什么特别之处吗?我的文件存在,但是显示"There was an error opening this document. The file cannot be found."我已经卸载了adobe 11并安装了adobe reader 10,那时代码完全正常运行。同时,使用命令行打开Acrobat Reader 11也能正常工作并打开PDF文件。


你收到了什么错误信息? - Esoteric Screen Name
1
这段代码通过在cmd中手动运行可以工作吗? - Despertar
@EsotericScreenName:错误信息为“打开文档时出错。找不到文件。” - rookie_developer
1
你能否直接调用静态 Process.Start(filename,arguments) 而不是创建对象?Process.Start("C:\example.pdf", "/A "page=2=OpenActions"); 看看是否可以启动 Adobe 11。 - B L
@RyanGates:当我只传入文件(例如:Process.Start( _PDFFileName );)时,它可以正常工作。 - rookie_developer
显示剩余7条评论
4个回答

4

请确保文件名中没有空格。在所有其他 Adobe Reader 中,如果有空格,它们可以正常工作,但 Adobe Reader 11 不支持。

希望这可以帮到您。


1
问题是由于文件名中的空格引起的。将下面的行更改为myProcess.StartInfo.Arguments = "/A \"page=2=OpenActions\" \"C:\\Jack and Jill.pdf\""; - rookie_developer

0
根据打开PDF文件的参数,您的参数行应该如下所示:
myProcess.StartInfo.Arguments = "/A \"page=2\" C:\\example.pdf";

0

请确保文件 C:\example.pdf 存在。当文件不存在时,会出现此错误。

string pdfPath = @"C:\example.pdf";

if (System.IO.File.Exists(pdfPath))
{
     System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
     myProcess.StartInfo.FileName = "AcroRd32.exe";
     myProcess.StartInfo.Arguments = string.Format("/A \"page=2=OpenActions\" \"{0}\"", pdfPath);
     myProcess.Start();
}

该文件确实存在,并且当我从命令提示符中执行它时,它会打开。 - rookie_developer

0

Reader 11的打开参数已更改或被删除。 请使用Reader 10。 我已向Adobe询问有关Reader 11打开参数的信息,但未收到回复。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接