There is a great Java package for displaying PDF files inside your Java application: PDFRenderer, developed as part of the java.net approach (javadesktop/swinglabs). Unfortunately, the order in which you do certain things is very important.
So, you need to do the following (in the Code):
- Create the JFrame, and create and add the PagePanel from PDFRenderer
- Show the JFrame (
- Show the PDF page you want to show (
This seems trivial, is done this way in the samples, yet ... change the order, and the only thing you get is "no page seleceted".
- setVisible before adding PagePanel: "no page selected"
- setVisible after showPage: "no page selected"
- adding PagePanel to a visible JFrame: "no page selected"
- showPage in an invisble JFrame: "no page selected"
- and so on ;-)
Great software, isn't it?
By the way, it can only show pdf version 1.4 (from Acrobat/Reader 5.0), and if there is a problem, you get an exception trace to System.err, yet no way to catch the exception ... the display is running asynchronously in a thread of its own.