Java PDF Viewer

Have a look at these free pdf renderer …

Some links …

  1. http://www.icepdf.org/ (now at http://www.icesoft.org/java/projects/ICEpdf/overview.jsf – Apache 2 Open Source)

  2. http://www.jpedal.org/support_siEclipse.php (now at https://www.idrsolutions.com/jpedal/ – commercial)

  3. https://java.net/projects/pdf-renderer (still available https://github.com/yarick123/pdf-renderer – LGPL-2.1)

UPDATE

As per http://www.icepdf.org/ ,

ICEpdf is an open source Java PDF
engine that can render, convert, or
extract PDF content within any Java
application or on a Web server.

For basic functionality you have to include icepdf-core.jar and icepdf-viewer.jar in your class path. Depending upon the requirement you can also add the SVG support.

Taken from iceface sample folder:

import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;

import javax.swing.*;

/**
 * The <code>ViewerComponentExample</code> class is an example of how to use
 * <code>SwingController</code> and <code>SwingViewBuilder</code>
 * to build a PDF viewer component.  A file specified at the command line is
 * opened in a JFrame which contains the viewer component.
 *
 * @since 2.0
 */
public class ViewerComponentExample {
    public static void main(String[] args) {
        // Get a file from the command line to open
        String filePath = args[0];

        // build a component controller
        SwingController controller = new SwingController();

        SwingViewBuilder factory = new SwingViewBuilder(controller);

        JPanel viewerComponentPanel = factory.buildViewerPanel();

        // add interactive mouse link annotation support via callback
        controller.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(
                        controller.getDocumentViewController()));

        JFrame applicationFrame = new JFrame();
        applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        applicationFrame.getContentPane().add(viewerComponentPanel);

        // Now that the GUI is all in place, we can try openning a PDF
        controller.openDocument(filePath);

        // show the component
        applicationFrame.pack();
        applicationFrame.setVisible(true);
    }
}

The above code helps you in displaying a PDF on a swing component. You can do the same in the SWT environment (have a look at SwingViewBuilder .. kind of hard, but will SWT look and feel ) or use org.eclipse.swt.awt.SWT_AWT (kind of easy… but will have swing + swt look and feel)… though both approach will solve your purpose. Also check the applicable licenses in the license folder.

Hope this will help.

Leave a Comment