本文介绍了我怎样才能在java中打开.pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我开发基于桌面的应用程序时,有一个.pdf格式的用户手册,应该在用户点击帮助菜单项时打开。
As I'm developing a desktop based application, there's a user manual in .pdf format which should be opened while user click on a help menu item.
我不知道从swing应用程序打开.pdf文件的方法,所以如何在我的 jframe中打开它
或任何pdf文件查看器,如acrobat reader。
I don't know the way to open .pdf file from swing application, so how can i get it open in my jframe
or in any pdf file viewer such as acrobat reader.
推荐答案
ActionListener listener = new MyListener();
butt.addActionListener(listener);
在我的监听器中添加此
if (Desktop.isDesktopSupported()) {
try {
File myFile = new File( "path/to/file");
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
// no application registered for PDFs
}
}
这篇关于我怎样才能在java中打开.pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!