Opening a PDF in a desktop application in Java

2020-04-12 07:43发布

Is it possible to open or create a PDF file in a Java desktop application just like we can create text file?

From my search I got that it is possible only with web java. Is that true?

标签: java pdf
4条回答
▲ chillily
2楼-- · 2020-04-12 07:50

To open an existing PDF file in the desktop default reader you can use the following code:

File pdf = new File("/path/to/your.pdf");
Desktop.getDesktop().open(pdf);

(needs Java 6)

查看更多
一夜七次
3楼-- · 2020-04-12 07:59

You can not create PDF just like a normal Text file, you will need PDF Library to create one. Opening an existing PDF is possible like *a_horse_with_no_name* mentioned in his answer.

You can find some PDF Libraries here.

查看更多
Melony?
4楼-- · 2020-04-12 08:02

You can use iText to do this. Here is a nice tutorial.

查看更多
劫难
5楼-- · 2020-04-12 08:06

There is an OS PDF plugin for Netbeans at http://www.jpedal.org/support_siNetBeans.php

查看更多
登录 后发表回答