com.qoppa.pdfWriter
Class PDFDocument

java.lang.Object
  extended bycom.qoppa.pdfWriter.PDFDocument

public class PDFDocument
extends Object

PDF document object. This class is used to create PDF documents from Java programs.
The steps to create a document are:

  1. Create a PDFDocument object.
  2. Create PDF pages by calling createPage.
  3. Draw to the PDF pages by getting a Graphics2D object from them and drawing to it.
  4. Add the PDF pages to the document.
  5. Save the document to a file or output stream.


    Field Summary
     String PAGEMODE_FULLSCREEN
              Full-screen mode, with no menu bar, window controls, or any other window visible
     String PAGEMODE_USEATTACHMENTS
              (PDF 1.6) Attachments panel visible
     String PAGEMODE_USENONE
              Neither document outline nor thumbnail images visible
     String PAGEMODE_USEOC
              (PDF 1.5) Optional content group panel visible
     String PAGEMODE_USEOUTLINES
              Document outline visible
     String PAGEMODE_USETHUMBS
              Thumbnail images visible
    static int PERMISSION_COPY_TEXT_GRAPHICS
              Permission flag to copy / extract text from the document.
    static int PERMISSION_MODIFY_ANNOTATIONS
              Permission flag to add / modify annotations.
    static int PERMISSION_MODIFY_CONTENTS
              Permission flag to modify the contents.
    static int PERMISSION_PRINT_DOCUMENT
              Permission flag to print the document.
     
    Constructor Summary
    PDFDocument()
              Constructs a new PDF document.
     
    Method Summary
     void addPage(PDFPage page)
              Adds a page to this document.
     PDFPage createPage(PageFormat pf)
              Creates a new PDFPage.
     Font embedFont(String fileName, int fontFormat, float size)
              Embeds a font in the PDF file.
    static PageFormat getDefaultPageFormat()
              Returns default page format for PDF documents.
     PDFPage getPage(int index)
              Returns the PDFPage object corresponding to the given index.
     int getPageCount()
              Returns the number of pages in the document.
    static String getVersion()
              Returns version string for the jPDFWriter.
    static PDFDocument loadHTML(byte[] htmlContent, URL baseURL, PageFormat pf, boolean fitToPage)
              Creates a PDFDocument from a byte array containing HTML script.
    static PDFDocument loadHTML(URL url, PageFormat pf, boolean fitToPage)
              Creates a PDFDocument from an HTML URL.
    static PDFDocument loadRTF(String rtfFile, PageFormat pf)
              Creates a PDFDocument from an RTF file.
     void saveDocument(OutputStream outStream)
              Saves this document to an output stream.
     void saveDocument(String fileName)
              Saves this document to a PDF file.
     void saveDocument(String fileName, int numCopies)
              Saves this document to a PDF file and replicates the document to simulate number of copies.
     void setDocumentInfo(DocumentInfo docInfo)
              Sets document information, such as the author, creation date and more.
     void setEncryption(String ownerPwd, String userPwd, int permissions)
              Sets the encryption for this document.
    static void setKey(String key)
              Sets product key.
     void setPageMode(String pageMode)
              Changes the value of the page mode viewer preference in the document.
     
    Methods inherited from class java.lang.Object
    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    PERMISSION_PRINT_DOCUMENT

    public static final int PERMISSION_PRINT_DOCUMENT
    Permission flag to print the document.

    See Also:
    Constant Field Values

    PERMISSION_MODIFY_CONTENTS

    public static final int PERMISSION_MODIFY_CONTENTS
    Permission flag to modify the contents.

    See Also:
    Constant Field Values

    PERMISSION_COPY_TEXT_GRAPHICS

    public static final int PERMISSION_COPY_TEXT_GRAPHICS
    Permission flag to copy / extract text from the document.

    See Also:
    Constant Field Values

    PERMISSION_MODIFY_ANNOTATIONS

    public static final int PERMISSION_MODIFY_ANNOTATIONS
    Permission flag to add / modify annotations.

    See Also:
    Constant Field Values

    PAGEMODE_USENONE

    public String PAGEMODE_USENONE
    Neither document outline nor thumbnail images visible


    PAGEMODE_USEOUTLINES

    public String PAGEMODE_USEOUTLINES
    Document outline visible


    PAGEMODE_USETHUMBS

    public String PAGEMODE_USETHUMBS
    Thumbnail images visible


    PAGEMODE_FULLSCREEN

    public String PAGEMODE_FULLSCREEN
    Full-screen mode, with no menu bar, window controls, or any other window visible


    PAGEMODE_USEOC

    public String PAGEMODE_USEOC
    (PDF 1.5) Optional content group panel visible


    PAGEMODE_USEATTACHMENTS

    public String PAGEMODE_USEATTACHMENTS
    (PDF 1.6) Attachments panel visible

    Constructor Detail

    PDFDocument

    public PDFDocument()
    Constructs a new PDF document.

    Method Detail

    loadRTF

    public static PDFDocument loadRTF(String rtfFile,
                                      PageFormat pf)
                               throws IOException,
                                      BadLocationException
    Creates a PDFDocument from an RTF file. The document will create as many pages as needed to draw the full RTF document.

    Parameters:
    rtfFile - - Name of the RTF file.
    pf - - PageFormat to use when creating pages in the PDF document.
    Throws:
    IOException
    BadLocationException

    loadHTML

    public static PDFDocument loadHTML(URL url,
                                       PageFormat pf,
                                       boolean fitToPage)
                                throws IOException,
                                       BadLocationException
    Creates a PDFDocument from an HTML URL. The document will create as many pages as needed to draw the full HTML page.

    Parameters:
    url - - url pointing to the HTML content.
    pf - - PageFormat to use when creating pages in the PDF document.
    fitToPage - - Set to shrink the document so that pages fit horizontally.
    Throws:
    IOException
    BadLocationException

    loadHTML

    public static PDFDocument loadHTML(byte[] htmlContent,
                                       URL baseURL,
                                       PageFormat pf,
                                       boolean fitToPage)
                                throws IOException,
                                       BadLocationException
    Creates a PDFDocument from a byte array containing HTML script. The document will create as many pages as needed to draw the full HTML content.

    Parameters:
    htmlContent - - byte array containing HTML script.
    baseURL - - URL to use when using relative references within the HTML content.
    pf - - PageFormat to use when creating pages in the PDF document.
    fitToPage - - Set to shrink the document so that pages fit horizontally.
    Throws:
    IOException
    BadLocationException

    createPage

    public PDFPage createPage(PageFormat pf)
    Creates a new PDFPage. This method DOES NOT add the page to the document, it simply creates it and returns it. After drawing to the page, addPage must be called to add the page to the document.

    Parameters:
    pf - The format of the new page.

    addPage

    public void addPage(PDFPage page)
    Adds a page to this document.

    Parameters:
    page - The new page.

    getPage

    public PDFPage getPage(int index)
    Returns the PDFPage object corresponding to the given index. The first page is index 0, the last page is getPageCount()-1. This method does no range checking, so it will throw an ArrayIndexOutOfBounds exception if the index is out of bounds.
    The PDFPage object can then be used to add more content to the given page by calling createGraphics and drawing into the Graphics object.

    Parameters:
    index - The index of the desired page.
    Returns:
    The PDFPage object at the given index.

    getPageCount

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

    Returns:
    Number of pages in the document.

    saveDocument

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

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

    saveDocument

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

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

    saveDocument

    public void saveDocument(String fileName,
                             int numCopies)
                      throws IOException
    Saves this document to a PDF file and replicates the document to simulate number of copies.

    Parameters:
    fileName - The name of the output file.
    numCopies - The number of copies of the document.
    Throws:
    IOException

    getVersion

    public static final String getVersion()
    Returns version string for the jPDFWriter.


    getDefaultPageFormat

    public static PageFormat getDefaultPageFormat()
    Returns default page format for PDF documents. This is an 8 1/2 by 11 page with no margins.

    Returns:
    the default page format.

    setKey

    public static void setKey(String key)
    Sets product key. Use this method after purchasing to remove evaluation restrictions.

    Parameters:
    key - - Product key.

    setEncryption

    public void setEncryption(String ownerPwd,
                              String userPwd,
                              int permissions)
    Sets the encryption for this document. Passing null values for the passwords means the document should not be encrypted.

    Parameters:
    ownerPwd - The document's owner password.
    userPwd - The document's user password.
    permissions - Permission bits. The value of this parameter should be the or'ed values of the constant values PERMISSION_PRINT_DOCUMENT, PERMISSION_MODIFY_CONTENTS, PERMISSION_COPY_TEXT_GRAPHICS and PERMISSION_MODIFY_ANNOTATIONS. Passing a value of 0 means that no permissions will be granted.

    setDocumentInfo

    public void setDocumentInfo(DocumentInfo docInfo)
    Sets document information, such as the author, creation date and more.

    Parameters:
    docInfo - The document information.

    embedFont

    public Font embedFont(String fileName,
                          int fontFormat,
                          float size)
                   throws IOException,
                          FontFormatException
    Embeds a font in the PDF file. Use this method to use custom fonts when creating a PDF file. The method returns a Font object that can then be used in the setFont method of Graphics2D. The fonts returned by this method can be used to generate different sizes using deriveFont, but not to generate different styles (bold, italic)

    Parameters:
    fileName - Name of the font file.
    fontFormat - Font format. This can be Font.TRUETYPE_FONT or Font.TYPE1_FONT (if using JDK1.5)
    Returns:
    Font - The newly created Font object. This can be used in Graphics2d.setFont().
    Throws:
    IOException
    FontFormatException

    setPageMode

    public void setPageMode(String pageMode)
    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 the following predefined constants:
    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. PAGEMODE_USEOC: (PDF 1.5) Optional content group panel visible PAGEMODE_USEATTACHMENTS: (PDF 1.6) Attachments panel visible