Site iconJava PDF Blog

How to view PDF files in Java (Tutorial)

Java PDF viewer

If you want to view PDF files in your Java application you will quickly find that Java has no native support for the PDF file format. It is for this reason that you would need a Java PDF viewer.

Today I’m going to walk you through the steps required to use the PDF Viewer in JPedal  (a Java library to Convert, Print, View PDF files). Once installed you will have a Java PDF API to access all aspects of the viewer from your Java code.

How to open PDF files in Java with Maven

There are a few ways you can install JPedal, you can either download the trial JAR from our website, or you can add JPedal to your project dependencies. This will allows you to view PDF documents in Java.

In this tutorial, I am going to be using Maven however you can also use Gradle.


You can find the latest version number of JPedal on our support site.

Once you have the dependency setup, you can use the code below to view PDF in Java.

How to view the PDF files from the Command line

If you want to quickly view PDF files, you may use the JPedal Viewer. To launch the viewer you can double-click to open the JAR or you can run the following:

How to view the PDF files in an existing Java application

JPedal provides a very easy to use Java PDF API for adding a PDF Viewer to your Java code. JPedal includes a single Viewer class to open and view PDF files. Creating an instance of the JPedal Viewer only requires two lines of code:


You can then use the following to open and display a PDF file:

How to customise your Java PDF Viewer

You may want to customise the look and feel of the PDF view, for example you might not want customers to be able to print your PDFs, or you might want to hide the menu buttons.

All of this and more is possible using a properties profile:

Learn more

Visit www.idrsolutions.com/jpedal to learn more about JPedal.

Visit support.idrsolutions.com/jpedal for comprehensive documentation and tutorials.