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 our JPedal Java PDF Library. Once installed you will have a Java PDF API to access all aspects of the viewer from your Java code.
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.
IDRsolutions IDR Solutions https://maven.idrsolutions.com com.idrsolutions jpedal-trial 2022.10
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.
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:
java -jar jpedal.jar --view [optional/filename.pdf]
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:
Viewer viewer = new Viewer(); viewer.setupViewer();
You can then use the following to open and display a PDF file:
viewer.executeCommand(Commands.OPENFILE, new Object[] );
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:
Viewer viewer = new Viewer("path/to/prefs.xml");
Visit www.idrsolutions.com/jpedal to learn more about JPedal.
Visit support.idrsolutions.com/jpedal for comprehensive documentation and tutorials.
Viewer viewer = new Viewer(); viewer.setupViewer(); viewer.executeCommand(ViewerCommands.OPENFILE, "pdfFile.pdf");
//Convenience static method (see class for additional options) ExtractClippedImages.writeAllClippedImagesToDir("inputFileOrDirectory", "outputDir", "outputImageFormat", new String[] );
//Convenience static method (see class for additional options) ExtractTextAsWordList.writeAllWordlistsToDir("inputFileOrDirectory", "outputDir", -1);
//Convenience static method (see class for additional options) ArrayList resultsForPages = FindTextInRectangle.findTextOnAllPages("/path/to/file.pdf", "textToFind");
PrintPdfPages print = new PrintPdfPages("C:/pdfs/mypdf.pdf"); if (print.openPDFFile())
//Convenience static method (see class for additional options) ExtractClippedImages.writeAllClippedImagesToDir("inputFileOrDirectory", "outputDir", "outputImageFormat", new String[] );