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, IPassword password)
          Loads a PDF document from an InputStream.
PDFPrint(String fileName, IPassword password)
          Loads a PDF document from a file.
PDFPrint(URL url, IPassword password)
          Loads a PDF document from a URL.
 
Method Summary
 Pageable getPageable(PrinterJob pJob)
          Returns an object that implements Pageable for this PDF document.
 int getPageCount()
          Returns the number of pages in this 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.
 boolean isPrintAllowed()
          Returns whether this document has permissions to print.
 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, IPassword password)
          Convenience method to print a PDF document from a file.
 void print(String printerName, PrintSettings printSettings, PrintRequestAttributeSet printAttrSet)
          Prints this PDF document to the specified printer, by name and passes the attribute set to the printer job.
static void print(String fileName, String printerName, PrintSettings printSettings, IPassword password)
          Convenience method to print a PDF document from a file to a named printer.
 void printToDefaultPrinter(PrintSettings printSettings)
          Prints the PDF document to the default printer.
static boolean setAppletKey(String key, Applet applet)
          Method to unlock the production version of the library.
static boolean 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,
                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.

PDFPrint

public PDFPrint(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.

PDFPrint

public PDFPrint(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

print

public static void print(String fileName,
                         PrintSettings printSettings,
                         IPassword password)
                  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.
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.
Throws:
PrinterException
PDFException

print

public static void print(String fileName,
                         String printerName,
                         PrintSettings printSettings,
                         IPassword password)
                  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.
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.
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. This method will print the PDF document silently (without showing the printer dialog) to the named printer. 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

print

public void print(String printerName,
                  PrintSettings printSettings,
                  PrintRequestAttributeSet printAttrSet)
           throws PDFPermissionException,
                  PrinterException
Prints this PDF document to the specified printer, by name and passes the attribute set to the printer job. This method will print the PDF document silently (without showing the printer dialog) to the named printer. If the printerName parameter is null, this method will print to the default printer. If the printAttrSet parameter is null, the printer job will use its default settings.

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.
printAttrSet - The attribute set to pass to the printer. This parameter simply gets passed through to the printer job to set options such as the media tray, chromaticity and others. If null is passed, the print job will use default attributes.
Throws:
PrinterException - This exception is thrown if the printer is not found or if there is an error while printing.
PDFPermissionException

printToDefaultPrinter

public void printToDefaultPrinter(PrintSettings printSettings)
                           throws PDFPermissionException,
                                  PrinterException
Prints the PDF document to the default printer. This method will print the PDF document silently (without showing the printer dialog) to the default printer.

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:
PrinterException - This exception is thrown if the printer is not found or if there is an error while printing.
PDFPermissionException

setKey

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

Parameters:
key - Production key.

setAppletKey

public static boolean 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

getPageCount

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


isPrintAllowed

public boolean isPrintAllowed()
Returns whether this document has permissions to print.

Returns:
Boolean flag indicating if this document has permissions to print.