Tuesday, May 5, 2009

ICeFaces open sources its pdf renderer

Hi All,

ICEFaces big name in the Ajax based JSF components has open sourced its famous pdf viewer component. Its commerical part only has additional Font engine.

In this post, I am posting an example about using ICEPdf viewer library for swing applications as I am a big fan of swing rich clients.

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();

JFrame applicationFrame = new JFrame();
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);
}
}

Actually, this example is taken from the ICEPdf distribution. It is a well-explained example. I found this example as very easy to use and it has all required features we usually need in PDF viewer.

Before this api, I was using Adobe abandoned "bean" project which has very old version of pdf render. I also tried pdf-renderer project hosted by java.dev.net. I found this library as very optimised and well-coded.

Cheers and enjoy ICEPDf

No comments: