如何在Java Swings中打开PDF文件 [英] How to Open PDF file in Java Swings

查看:106
本文介绍了如何在Java Swings中打开PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对Java Swings非常陌生我需要从Swings应用程序打开PDF文件..

我尝试如下......


运行时r = Runtime.getRuntime();

进程p = r.exec(" C:/ Program Files / Adob​​e / Reader 8.0 / Reader / AcroRd32.exe Test.Pdf");


它运行了..但是其他任何解决方案..因为我很难编写exe文件的路径以上代码....

pl尽快帮助我...

Hi All,
I am very much new to java Swings I need to open the PDF file from Swings application..
I tried as follows...

Runtime r= Runtime.getRuntime();
Process p = r.exec("C:/Program Files/Adobe/Reader 8.0/Reader/AcroRd32.exe Test.Pdf");


it got work.. But is ter any other solution.. because am hard coding the path of the exe file in the above code....
pl help me out ASAP...

推荐答案

1。使用注册表类确定用于打开.pdf文件的文件。

HKEY_CURRENT_USER \Software \ Mycoftoft \ Windows \Curre ntVersion\Explorer \FileExts\.pdf \ OpenWithList

HKEY_CURRENT_USER \Software \ Microsoft \ Windows \Curre ntVersion \Explorer \FileExts\.pdf \ OpenWithProgids


然后你可以处理用户没有安装.pdf阅读器的情况,将它们引导到FoxIt的网站或其他.pdf阅读器网站。


2.您可以将exe文件的名称作为String变量传递。例如从你的String [] args中获取它。
1. Use the registry class to determine what file is used to open a .pdf file.
HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\FileExts\.pdf\OpenWithList
HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\FileExts\.pdf\OpenWithProgids

You could then handle the case where the user does not have .pdf reader installed, by directing them to FoxIt''s website, or some other .pdf reader site.

2.You could pass the name of the exe file in as a String variable. eg get it from your String[] args.


谢谢。你能否请你的第一个解决方案......以及任何其他解决方案。
Thanks. Could you please brief your first solution.. And any other solutions.


java.awt.Desktop有一个 open()方法。
java.awt.Desktop has an open() method.


这篇关于如何在Java Swings中打开PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆