com.qoppa.pdfPrint
Class PDFPrint

java.lang.Object
  extended bycom.qoppa.pdfPrint.PDFPrint
All Implemented Interfaces:
Printable

public class PDFPrint
extends Object
implements Printable

The PDFPrint class provides methods to print a pdf document.

Author:
Qoppa Software

Field Summary
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PDFPrint(InputStream inStream, IPasswordHandler pwdHandler)
          Loads a PDF document from an InputStream.
PDFPrint(String fileName, IPasswordHandler pwdHandler)
          Loads a PDF document from a file.
PDFPrint(URL url, IPasswordHandler pwdHandler)
          Loads a PDF document from a URL.
 
Method Summary
 int getNumberOfPages()
          Returns the number of pages in this document.
 Pageable getPageable(PrinterJob pJob)
          Returns an object that implements Pageable for this PDF document.
 PageFormat getPageFormat(int pageIndex)
          Returns a PageFormat object for the given page.
 PrintSettings getPrintSettings()
          Returns the PrintSettings that will be used when printing the document.
static String getVersion()
          Returns version string for jPDFPrint.
 int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
          Prints the page.
 void print(PrintSettings printSettings)
          Prints this PDF document.
 void print(String printerName, PrintSettings printSettings)
          Prints this PDF document to the specified printer, by name.
static void print(String fileName, PrintSettings printSettings, IPasswordHandler pwdHandler)
          Convenience method to print a PDF document from a file.
static void print(String fileName, String printerName, PrintSettings printSettings, IPasswordHandler pwdHandler)
          Convenience method to print a PDF document from a file to a named printer.
static void setAppletKey(String key, Applet applet)
          Method to unlock the production version of the library.
static void setKey(String key)
          Method to unlock the production version of the library.
 void setPrintSettings(PrintSettings printSettings)
          Set the PrintSettings used when printing this document while using the class as a Printable (rather than calling one of the print methods).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFPrint

public PDFPrint(String fileName,
                IPasswordHandler pwdHandler)
         throws PDFException
Loads a PDF document from a file.

Parameters:
fileName - Name of the PDF file.
pwdHandler - Interface to provide a password, if necessary.

PDFPrint

public PDFPrint(InputStream inStream,
                IPasswordHandler pwdHandler)
         throws PDFException
Loads a PDF document from an InputStream.

Parameters:
inStream - InputStream to read the PDF document.
pwdHandler - Interface to provide a password, if necessary.

PDFPrint

public PDFPrint(URL url,
                IPasswordHandler pwdHandler)
         throws PDFException
Loads a PDF document from a URL.

Parameters:
url - Location of the PDF document.
pwdHandler - Interface to provide a password, if necessary.
Method Detail

print

public static void print(String fileName,
                         PrintSettings printSettings,
                         IPasswordHandler pwdHandler)
                  throws PrinterException,
                         PDFException
Convenience method to print a PDF document from a file. This method will prompt the user with the printer dialog and then print the document. This method is equivalent to:

PDFPrint pdfPrint = new PDFPrint (fileName, pwdHandler);
pdfPrint.print (printSettings);

Parameters:
fileName - Name of the PDF file.
printSettings - Print job settings. Use this object to tell the library how to print the document. The library uses default settings when null is used.
pwdHandler - Interface to provide a password, if necessary.
Throws:
PrinterException
PDFException

print

public static void print(String fileName,
                         String printerName,
                         PrintSettings printSettings,
                         IPasswordHandler pwdHandler)
                  throws PrinterException,
                         PDFException
Convenience method to print a PDF document from a file to a named printer. This method is equivalent to:

PDFPrint pdfPrint = new PDFPrint (fileName, pwdHandler);
pdfPrint.print (printerName, printSettings);

Parameters:
fileName - Name of the PDF file.
printerName - Name of the printer to print to. If null, prints to the default printer.
printSettings - Print job settings. Use this object to tell the library how to print the document. The library uses default settings when null is used.
pwdHandler - Interface to provide a password, if necessary.
Throws:
PrinterException
PDFException

print

public void print(PrintSettings printSettings)
           throws PDFPermissionException,
                  PrinterException
Prints this PDF document. This method will prompt the user with the printer dialog and then print the document.

If finer control of printing is necessary, the PDFPrint object implements both Printable and Pageable (through the getPageable method). The host application can then create its own PrinterJob and set any settings necessary, then call either setPageable or setPrintable and then start the print job.

Parameters:
printSettings - Print job settings. Use this object to tell the library how to print the document. If null, the library will print using default settings.
Throws:
PDFPermissionException
PrinterException

print

public void print(String printerName,
                  PrintSettings printSettings)
           throws PDFPermissionException,
                  PrinterException
Prints this PDF document to the specified printer, by name. If the printerName parameter is null, this method will print to the default printer. This method can only be called if using Java 1.4.2 or higher as it needs PrintServices, which were only implemented starting on 1.4.

If finer control of printing is necessary, the PDFPrint object implements both Printable and Pageable (through its getPageable method). The host application can then create its own PrinterJob and set any settings necessary, then call either setPageable or setPrintable and then start the print job.

Parameters:
printSettings - Print job settings. Use this object to tell the library how to print the document. If null, the library will print using default settings.
printerName - The name of the printer to print to. If this parameter is set to null, the method will print to the default printer.
Throws:
PrinterException - This exception is thrown if the printer is not found or if there is an error while printing.
PDFPermissionException

setKey

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

Parameters:
key - Production key.

setAppletKey

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

Parameters:
key - Production key.

getVersion

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


print

public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
          throws PrinterException
Prints the page. This method fulfills the Printable interface and usually gets called by PrinterJob when printing the document.

Specified by:
print in interface Printable
Throws:
PrinterException

getPrintSettings

public PrintSettings getPrintSettings()
Returns the PrintSettings that will be used when printing the document.

Returns:
PrintSettings Print settings used when printing.

getPageable

public Pageable getPageable(PrinterJob pJob)
Returns an object that implements Pageable for this PDF document. The method takes a PrinterJob object as a parameter because information about the printer is needed in order to fulfill the Pageable interface properly.

Parameters:
pJob - PrinterJob object where the Pageable will be used.
Returns:
Object that implements the Pageable interface.

setPrintSettings

public void setPrintSettings(PrintSettings printSettings)
Set the PrintSettings used when printing this document while using the class as a Printable (rather than calling one of the print methods).

Parameters:
printSettings - PrintSettings to use when printing.

getPageFormat

public PageFormat getPageFormat(int pageIndex)
                         throws IndexOutOfBoundsException
Returns a PageFormat object for the given page. Page indices are 0 based (1st page is pageIndex 0).

Returns:
PageFormat A PageFormat object describing the page dimensions.
Throws:
IndexOutOfBoundsException

getNumberOfPages

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