PDF Viewer as a JPanel in a NetBeans RCP Application
Join the DZone community and get the full member experience.
Join For FreeThe 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 PdfRenderer,
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 http://www.icepdf.org 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:
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 http://www.icepdf.org 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:
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
InputStream inputStream = MY_PDF_AS_STREAM;
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
MY_MAIN_PANEL.add(viewerComponentPanel, BorderLayout.CENTER);
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 http://pwnt.be/lab/jflow. 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!

Yes, I only offered two books to choose from...
Until next time!
Until next time!
PDF
Rich client platform
application
NetBeans
Opinions expressed by DZone contributors are their own.
Trending
-
Competing Consumers With Spring Boot and Hazelcast
-
Mastering Time Series Analysis: Techniques, Models, and Strategies
-
MLOps: Definition, Importance, and Implementation
-
SRE vs. DevOps
Comments