The project I'm working on is run by a
book publishing company
in Sweden. So for them to want to be able to provide integrated support for PDF viewing in the product seemed fairly obvious. After spending quite some time googling for different derivatives of "open source pdf jpanel swing" and such, I first found
, an original SwingLabs project that seemed to not be worked on at that time (but perhaps will be restarting soon? Keep an eye on that link if you're interested, I know I will).
There are multiple options if you're looking for commercially licensed products and, what seem like, good ones too. But I wanted open source. After a while I found
and it seemed like their
mozilla public licensed
ICEpdf project offered what I was looking for.
What I wanted was fairly simple. I had a pdf file and wanted a viewer panel extending JPanel.
And voila, this is how my code ended up looking:
InputStream inputStream = MY_PDF_AS_STREAM;
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
controller.openDocument(inputStream, "", "");
And this is what I got, in our NetBeans RCP application:
As you can see, all expected icons are there... The PDF functionality includes everything I expected (as search, text selections and links). All in all, I think ICEpdf is a pretty nice acquaintance.
Oh, and if you've read this far, you might like what I used for selecting what PDF to view. I found
. I know that it has been done before, but in this case I actually think a Cover Flow selection component actually adds some value as well as some sexy. The excellent JFlow project required only very light tweaking to fit my needs, so you might want to check that out!