com.qoppa.pdfAssemble
Class PDFAssemble

java.lang.Object
  extended bycom.qoppa.pdfAssemble.PDFAssemble

public class PDFAssemble
extends Object

The PDFAssemble class provides methods to assemble and disassemble PDF documents. The PDFAssemble class can load existing documents (or start from a blank document) and can add pages from other documents or delete pages in the document.

Author:
Qoppa Software

Field Summary
static String MAGNIFICATION_FIT_ACTUAL
          Setting for the initial magnification: 100% Scale
static String MAGNIFICATION_FIT_HEIGHT
          Setting for the initial magnification: Fit to height
static String MAGNIFICATION_FIT_PAGE
          Setting for the initial magnification: Fit page (both width and height)
static String MAGNIFICATION_FIT_WIDTH
          Setting for the initial magnification: Fit to width
static String PAGELAYOUT_ONECOLUMN
          Setting for the initial page layout: Single page continuous
static String PAGELAYOUT_SINGLEPAGE
          Setting for the initial page layout: Single page
static String PAGELAYOUT_TWOCOLUMNLEFT
          Setting for the initial page layout: Two pages continuous
static String PAGELAYOUT_TWOPAGELEFT
          Setting for the initial page layout: Two pages
static String PAGEMODE_FULLSCREEN
          Setting for the initial page mode: Full-screen mode, with no menu bar, window controls, or any other window visible
static String PAGEMODE_USEATTACHMENTS
          Setting for the initial page mode: (PDF 1.6) Attachments panel visible
static String PAGEMODE_USENONE
          Setting for the initial page mode: Neither document outline nor thumbnail images visible
static String PAGEMODE_USEOC
          Setting for the initial page mode: (PDF 1.5) Optional content group panel visible
static String PAGEMODE_USEOUTLINES
          Setting for the initial page mode: Document outline visible
static String PAGEMODE_USETHUMBS
          Setting for the initial page mode: Thumbnail images visible
 
Constructor Summary
PDFAssemble()
          Creates a blank PDFAssemble object.
PDFAssemble(InputStream inStream, IPassword password)
          Loads a PDF document from an InputStream.
PDFAssemble(String fileName, IPassword password)
          Loads a PDF document from a file.
PDFAssemble(URL url, IPassword password)
          Loads a PDF document from a URL.
 
Method Summary
 void appendDocument(PDFAssemble appendDoc)
          Appends a PDF document to this document.
 void appendPage(PDFAssemble source, int pageIndex)
          Appends a page to this document.
 Bookmark createRootBookmark()
          Creates a new root bookmark and saves it in the document catalog.
 void deletePage(int pageIndex)
          Deletes a page from this document.
 void deletePages(int startIndex, int endIndex)
          Deletes a range of pages in the document.
 PDFAssemble extractPages(int startIndex, int endIndex, OutputStream outStream)
          Creates and saves a new PDF document that contains a range of pages from this document.
 PDFAssemble extractPages(int startIndex, int endIndex, String outputFile)
          Creates and saves a new PDF document that contains a range of pages from this document.
 DocumentInfo getDocumentInfo()
          Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)
 int getPageCount()
          Returns the number of pages in this document.
 PDFPermissions getPermissions()
          Returns the permission object for this document.
 Bookmark getRootBookmark()
          Returns the 'root' bookmark.
static String getVersion()
          Returns version string for jPDFFields.
 void insertPage(PDFAssemble sourceDoc, int srcPageIndex, int dstPageIndex)
          Inserts a page into this document at the given index.
 void saveDocument(OutputStream outStream)
          Saves this document to an output stream.
 void saveDocument(String fileName)
          Saves this document to a file.
static boolean setAppletKey(String key, Applet applet)
          Method to unlock the production version of the library.
 void setInitialMagnification(String magnification)
          Sets the magnification at which to display the initial view.
 void setInitialPage(int pageNumber)
          Sets the initial page to display.
 void setInitialPageLayout(String pageLayout)
          Changes the value of the page layout key for this document.
 void setInitialPageMode(String pageMode)
          Changes the value of the page mode viewer preference in the document.
static boolean setKey(String key)
          Method to unlock the production version of the library.
 boolean usePermissionsPassword(String ownerPassword)
          Tells the PDFDocument object that the permissions password is known, so all permissions are granted.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAGNIFICATION_FIT_WIDTH

public static final String MAGNIFICATION_FIT_WIDTH
Setting for the initial magnification: Fit to width

See Also:
Constant Field Values

MAGNIFICATION_FIT_HEIGHT

public static final String MAGNIFICATION_FIT_HEIGHT
Setting for the initial magnification: Fit to height

See Also:
Constant Field Values

MAGNIFICATION_FIT_PAGE

public static final String MAGNIFICATION_FIT_PAGE
Setting for the initial magnification: Fit page (both width and height)

See Also:
Constant Field Values

MAGNIFICATION_FIT_ACTUAL

public static final String MAGNIFICATION_FIT_ACTUAL
Setting for the initial magnification: 100% Scale

See Also:
Constant Field Values

PAGEMODE_USENONE

public static final String PAGEMODE_USENONE
Setting for the initial page mode: Neither document outline nor thumbnail images visible

See Also:
Constant Field Values

PAGEMODE_USEOUTLINES

public static final String PAGEMODE_USEOUTLINES
Setting for the initial page mode: Document outline visible

See Also:
Constant Field Values

PAGEMODE_USETHUMBS

public static final String PAGEMODE_USETHUMBS
Setting for the initial page mode: Thumbnail images visible

See Also:
Constant Field Values

PAGEMODE_FULLSCREEN

public static final String PAGEMODE_FULLSCREEN
Setting for the initial page mode: Full-screen mode, with no menu bar, window controls, or any other window visible

See Also:
Constant Field Values

PAGEMODE_USEOC

public static final String PAGEMODE_USEOC
Setting for the initial page mode: (PDF 1.5) Optional content group panel visible

See Also:
Constant Field Values

PAGEMODE_USEATTACHMENTS

public static final String PAGEMODE_USEATTACHMENTS
Setting for the initial page mode: (PDF 1.6) Attachments panel visible

See Also:
Constant Field Values

PAGELAYOUT_SINGLEPAGE

public static final String PAGELAYOUT_SINGLEPAGE
Setting for the initial page layout: Single page

See Also:
Constant Field Values

PAGELAYOUT_ONECOLUMN

public static final String PAGELAYOUT_ONECOLUMN
Setting for the initial page layout: Single page continuous

See Also:
Constant Field Values

PAGELAYOUT_TWOCOLUMNLEFT

public static final String PAGELAYOUT_TWOCOLUMNLEFT
Setting for the initial page layout: Two pages continuous

See Also:
Constant Field Values

PAGELAYOUT_TWOPAGELEFT

public static final String PAGELAYOUT_TWOPAGELEFT
Setting for the initial page layout: Two pages

See Also:
Constant Field Values
Constructor Detail

PDFAssemble

public PDFAssemble()
            throws PDFException
Creates a blank PDFAssemble object. This constructor can be used to create a new document entirely from other documents.


PDFAssemble

public PDFAssemble(InputStream inStream,
                   IPassword password)
            throws PDFException
Loads a PDF document from an InputStream.

Parameters:
inStream - InputStream to read the PDF document.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.

PDFAssemble

public PDFAssemble(String fileName,
                   IPassword password)
            throws PDFException
Loads a PDF document from a file.

Parameters:
fileName - Name of the PDF file.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.

PDFAssemble

public PDFAssemble(URL url,
                   IPassword password)
            throws PDFException
Loads a PDF document from a URL.

Parameters:
url - Location of the PDF document.
password - An object that provides passwords to open the document, leave null if not needed. When working with documents that have no passwords, the host application should pass null for the value of this parameter. When documents are known to have passwords, the host application should pass an instance of the PDFPassword class that can hold a single password or a list of passwords.
Method Detail

getPageCount

public int getPageCount()
Returns the number of pages in this document.


getDocumentInfo

public DocumentInfo getDocumentInfo()
Returns a DocumentInfo object containing the information section of a PDF document (author, title, etc.)

Returns:
DocumentInfo Object containing header information for the document.

getVersion

public static String getVersion()
Returns version string for jPDFFields. If this is the demo version, the return string will contain 'Demo Version' at the end.


appendDocument

public void appendDocument(PDFAssemble appendDoc)
                    throws PDFException
Appends a PDF document to this document. All the pages in appendDoc will be added at the end of this document.

Parameters:
appendDoc - Document to be appended.
Throws:
PDFException

appendPage

public void appendPage(PDFAssemble source,
                       int pageIndex)
                throws PDFException
Appends a page to this document.

Parameters:
source - The document from which to append the page.
pageIndex - The index of the page to append from the source document.
Throws:
PDFException

insertPage

public void insertPage(PDFAssemble sourceDoc,
                       int srcPageIndex,
                       int dstPageIndex)
                throws PDFException
Inserts a page into this document at the given index. If the index is less than 0, the page is inserted as the first page. If the index is greater than the number of pages in the document, the page is appended to the document.

Parameters:
sourceDoc - The document from which to append the page.
srcPageIndex - The index of the page to append from the source document.\
dstPageIndex - The index of the page at which to insert the new page.
Throws:
PDFException

deletePage

public void deletePage(int pageIndex)
                throws PDFException
Deletes a page from this document. If the index is out of bounds, (index < 0 or index >= number of pages) this method has no effect on the document.

Parameters:
pageIndex - Index of the page to remove.
Throws:
PDFException

deletePages

public void deletePages(int startIndex,
                        int endIndex)
                 throws PDFException
Deletes a range of pages in the document. The start and end index are 0 based and inclusive.

Parameters:
startIndex - The index of the first page to delete.
endIndex - The index of the last page to delete, inclusive.
Throws:
PDFException

extractPages

public PDFAssemble extractPages(int startIndex,
                                int endIndex,
                                String outputFile)
                         throws IOException,
                                PDFException
Creates and saves a new PDF document that contains a range of pages from this document.

Parameters:
startIndex - The first page to include in the new document.
endIndex - The last page to include in the new document.
outputFile - The path to the file to save the PDF document in.
Throws:
IOException - Any errors writing the file
PDFException - Any errors extracting the pages

extractPages

public PDFAssemble extractPages(int startIndex,
                                int endIndex,
                                OutputStream outStream)
                         throws IOException,
                                PDFException
Creates and saves a new PDF document that contains a range of pages from this document.

Parameters:
startIndex - The first page to include in the new document.
endIndex - The last page to include in the new document.
outStream - The output stream to write the new document to.
Throws:
IOException - Any errors writing the file
PDFException - Any errors extracting the pages

createRootBookmark

public Bookmark createRootBookmark()
                            throws PDFException
Creates a new root bookmark and saves it in the document catalog. When this method is called, any existing bookmarks will be discarded and the new root bookmark will be put in place. Initially, the new root bookmark will have no children (no entries will be displayed in the bookmarks pane when viewing the document).

Returns:
Bookmark The new root bookmark.
Throws:
PDFException

getRootBookmark

public Bookmark getRootBookmark()
Returns the 'root' bookmark. Bookmarks form a tree structure in a document.

Returns:
Bookmark The root bookmark for this document.

saveDocument

public void saveDocument(String fileName)
                  throws IOException,
                         PDFException
Saves this document to a file.

Parameters:
fileName - Name of the file to save the document.
Throws:
IOException
PDFException

saveDocument

public void saveDocument(OutputStream outStream)
                  throws IOException,
                         PDFException
Saves this document to an output stream.

Parameters:
outStream - OutputStream where the document will be written to.
Throws:
IOException
PDFException

setAppletKey

public static boolean setAppletKey(String key,
                                   Applet applet)
Method to unlock the production version of the library.

Parameters:
key - Production key.

setKey

public static boolean setKey(String key)
Method to unlock the production version of the library.

Parameters:
key - Production key.

usePermissionsPassword

public boolean usePermissionsPassword(String ownerPassword)
                               throws PDFException
Tells the PDFDocument object that the permissions password is known, so all permissions are granted. This method is here as a convenience so that if the owner password is known, the host application does not have to clear the security, make changes to the document, and then restore the security.

Parameters:
ownerPassword - The permissions password
Returns:
true if the password was validated
Throws:
PDFException

getPermissions

public final PDFPermissions getPermissions()
Returns the permission object for this document. A new permissions object with all permissions is returned if the document is not encrypted.

Returns:
The permission object.

setInitialPageMode

public void setInitialPageMode(String pageMode)
                        throws PDFException
Changes the value of the page mode viewer preference in the document. The page mode is used when the document is opened in a PDF Viewer.

Parameters:
pageMode - The new page mode. This value has to be one of:
PAGEMODE_USENONE: Neither document outline nor thumbnail images are visible.
PAGEMODE_USEOUTLINES: Document outline visible.
PAGEMODE_USETHUMBS: Thumbnail images visible.
PAGEMODE_FULLSCREEN: Full screen mode, with no menu bar, window controls, or any other window visible.
Throws:
PDFException

setInitialPageLayout

public void setInitialPageLayout(String pageLayout)
                          throws PDFException
Changes the value of the page layout key for this document. This determines the layout of the page when initially opened.

Parameters:
pageLayout - The new page mode. This value has to be one of:
PAGELAYOUT_SINGLEPAGE: Display one page at a time.
PAGELAYOUT_ONECOLUMN: Display the page in one column (single page continuous).
PAGELAYOUT_TWOCOLUMNLEFT: Display the page in two columns (two facing continuous).
PAGELAYOUT_TWOPAGELEFT: Display two pages at a time (two facing).
Throws:
PDFException

setInitialPage

public void setInitialPage(int pageNumber)
                    throws PDFException
Sets the initial page to display.

Parameters:
pageNumber - The page number. Use 0 for first page.
Throws:
PDFException

setInitialMagnification

public void setInitialMagnification(String magnification)
                             throws PDFException
Sets the magnification at which to display the initial view.

Parameters:
magnification - A string magnification. This value has to be one of:
MAGNIFICATION_FIT_WIDTH: Display with the page magnified just enough to fit the entire width of the page within the window.
MAGNIFICATION_FIT_HEIGHT: Display with the page magnified just enough to fit the entire height of the page within the window.
MAGNIFICATION_FIT_PAGE: Display with the page magnified just enough to fit the entire page within the window both horizontally and vertically .
MAGNIFICATION_FIT_ACTUAL: Display the page with 100% magnification.

A String value of a number, ex. "125"
A null value to clear the magnification
Throws:
PDFException