如何跳转到本地pdf中的页面?
我的问题类似于“我如何以编程方式在某个时刻打开 pdf?”,但 PDF 是本地的,而不是在 Web 服务器上。
我需要一种方法来跳转到用户计算机上的 PDF 中的给定页面,该页面可以跨版本的 Acrobat(或使用替代的 PDF 查看器,如 Foxit Reader)。 PDF 将从 Java 应用程序中调用(它仅在 Windows 上使用,因此跨平台不是必须的),现在它
int pageNum = 24;
String manualPath = "C:\\Program Files\\Foo\\Bar\\Docs\\RefMan.pdf";
String acrordPath = "C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe";
String cmdString = "\"" + acrordPath + \" /A \"page=" + pageNum +
"=OpenActions\" \"" + manualPath + \"";
Process p = Runtime.getRuntime().exec(cmdString);
可以使用: 显然,这仅在最终用户使用 Acrobat 8 时才有效对于 32 位,并将其安装在默认位置。 我接下来尝试使用:
rundll32 url.dll,FileProtocolHandler file:///C:/Program%20Files/Foo/Bar/Docs/RefMan.pdf#page=24
认为这会打开用户浏览器并跳转到该页面,但它只是在第 1 页上打开 Acrobat。
所以我被难住了,并寻求帮助。
My question is similar to "How can I programmaticly open a pdf at a certain point?", but the PDF is local, not on a web server.
I need a way to jump to a given page in a PDF that is on the users computer, that works across versions of Acrobat (or using an alternative PDF viewer like Foxit Reader). The PDF is going to be called from a Java app (it is only used on Windows, so cross-platform isn't a must), and right now it works with:
int pageNum = 24;
String manualPath = "C:\\Program Files\\Foo\\Bar\\Docs\\RefMan.pdf";
String acrordPath = "C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe";
String cmdString = "\"" + acrordPath + \" /A \"page=" + pageNum +
"=OpenActions\" \"" + manualPath + \"";
Process p = Runtime.getRuntime().exec(cmdString);
Obviously this will only work if the end user is using Acrobat 8 for 32bit, and installed it in the default location. I next tried using:
rundll32 url.dll,FileProtocolHandler file:///C:/Program%20Files/Foo/Bar/Docs/RefMan.pdf#page=24
thinking that this would open the users browser and jump to that page, but it simply opened Acrobat on page 1.
So I'm stumpped, and asking for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过使用 此代码 调用 reg.exe 并解析来实现此目的从 HKLM\SOFTWARE\Classes.pdf 的输出中查看是否是 AcroExch 类,然后从 HKLM\SOFTWARE\Classes\AcroExch.Document\Shell\Open\Command 获取命令行。
虽然很hacky,但是很有效。
I ended up implementing this by using this code to call reg.exe and parse the output from HKLM\SOFTWARE\Classes.pdf to see if its the AcroExch class, then getting the command line from HKLM\SOFTWARE\Classes\AcroExch.Document\Shell\Open\Command.
Its hacky, but it works.