Contents
Introduction
jPDFNotes
is a Java bean that can be embedded in Java applications and
applets to deliver PDF content to your users and allow them to add notes and comments and then save the annotated document. jPDFNotes is built on Qoppa's proprietary PDF technology and so does not need the installation of any third party software or drivers. jPDFNotes integrates seamlessly into your application or applet and delivers
the most features, performance and reliability of any Java PDF
viewer.
By using jPDFNotes in your application, you can implement custom document revision cycles with complete control and security over your PDF content. jPDFNotes lets you customize the functions available to your users, such as opening, saving and printing documents, so that you control the flow of content.......
Getting Started
jPDFNotes provides a standard Java bean that can be added to any GUI container, the bean class is com.qoppa.pdfNotes.PDFNotesBean. The bean can be added to a container either programmatically or using any standard GUI editor in your development environment. Once the bean has been added, your application can start showing PDF documents and your users can start adding notes and comments to them. jPDFNotes can load PDF documents both programmatically based on the application logic, or by letting users open their own PDF documents by clicking on the open button in the toolbar.
The host application can also customize the toolbar by calling the getToolbar() method and removing or adding buttons, override the button handlers, or even hiding the entire toolbar. Action handlers on the toolbar buttons can be overridden to provide custom code to handle the functions. For example, your application can override the open function to show the user a limited list of PDF documents that can be opened.
Opening a Document
Loading and
displaying a document programmatically is very simple using jPDFNotes. Once a
PDFNotesBean bean has been added to a container, the host application
simply needs to call one of the loadPDF methods
and the library will load and display the first page of the document.
The three versions of the loadPDF method take a file
name, a URL or an InputStream as parameters
PDFNotesBean
bean = getViewerBean ();
bean.loadPDF ("c:\\test.pdf");
Saving the Document
jPDFNotes provides a save button on the navigation toolbar, this button has the following default behaviour:
- If the PDF document was opened from the file system, jPDFNotes will save the modified document to the same location.
- If the PDF document was opened from a URL or from and InputStream, the library will prompt the user for a file name and save it to that location.
This default behaviour can be overridden by the host application by registering a PDF Saver with the PDFNotesBean. To do this, the host application needs to call the setPDFSaver method in the PDFNotesBean with an object that implements IPDFSaver. IPDFSaver is an interface that is called anytime that the PDFNotesBean needs to save a document. The interface consists of a single method with three parameters, the reference to the PDFNotesBean object, the name of the PDF document and if the document was opened from a file, a reference to a File object pointing to the file that the document was opened from.
The host application can use this to save the modified documents to locations other than the file system and with or without user intervention. For instance, the application might need to save the document to a database server or to an application server. Within the method, the host application can get a reference to the document by calling the getDocument method in the PDFNotesBean object. It can then use the PDFDocument object returned to write the PDF content to a file or to an OutputStream. By using a ByteArrayOutputStream, the application can get a byte array holding the contents of the PDF document.
Customizing the Toolbar
The toolbars
in jPDFNotes can be shown or hidden according to the needs of
host application. Additionally, all the buttons in the toolbar
are accessible, so they can be enabled/disabled or hidden. The
PDFNotesBean class provides two methods, getAnnotToolbar and getEditToolbar that return references to the annotations toolbar and the navigation toolbar respectively. Each of these toolbars provide methods to access the buttons within them so that the host application can disable or hide the buttons individually. Please refer to the API for
more detail.
The following
examples assume that notesBean is a reference to a
PDFNotesBean:
To hide the
annotations toolbar:
notesBean.getAnnotToolbar().setVisible
(false);
To hide the
open button:
notesBean.getEditToolbar().getjbOpen
().setVisible (false);
To disable
the print button:
notesBean.getToolbar().getjbPrint().setEnabled
(false);
Distribution and JAR Files
jPDFNotes is packaged entirely in a single jar file, jPDFNotes.jar that gets installed with the evaluation sample.
When deploying an application that contains jPDFNotes, the
jPDFNotes.jar file needs to be installed and included in the class path when running the application.
To support JPEG 2000 images, jPDFNotes uses the Java Advanced
Imaging (JAI) classes. Since this API is only available for Java
1.4.2, jPDFNotes needs to run in Java 1.4.2 or above when working
with PDF documents that contain JPEG 2000 images. The API can be
installed separately in the target machine or the jai_imageio.jar
file (included in the sample program installation) can be installed independently and included in the class path.