View PDF in Java

JPedal includes a very comprehensive PDF viewer which makes use of both Swing and JavaFX for the best possible viewing solution. It is written in Java but can be run from other languages or command line.

If you do not have a JPedal, you can download a trial copy from here.

View PDF files from Command Line or another language

java -jar jpedal.jar --view "pdfFile.pdf"

View PDF files in a new window with Java

Viewer viewer = new Viewer();
viewer.executeCommand(Commands.OPENFILE, new Object[]{"pdfFile.pdf"});

This uses the JPedal Viewer class. If you want to set a look and feel for the viewer standalone, you can as shown on this FAQ.

View PDF files in existing Java Application - add Viewer to another Swing Component

//Create display JFrame
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout());

//This could be any JPanel from your application
final JPanel rootContainer = frame.getContentPane();

Viewer viewer = new Viewer(rootContainer,null);
viewer.executeCommand(Commands.OPENFILE, new Object[]{"pdfFile.pdf"});

//add viewer to your application

//Display the example frame with embedded PDF viewer
frame.setTitle("Viewer in External Frame");

As well as adding the Viewer to your own application you can also customize the Viewer to control which options are present using the Viewers properties file. Once you have created a properties file that displays the options you require it can be loaded by the Viewers constructor shown above. To do this you just need to pass in the file’s path as the second parameter.

Still need help? Send us your questions.