com.icesoft.pdf.ri.common
Class PrintHelper

java.lang.Object
  extended bycom.icesoft.pdf.ri.common.PrintHelper
All Implemented Interfaces:
Pageable, Printable

public class PrintHelper
extends Object
implements Pageable, Printable

The PrintHelper class is utility class to aid developers in printing PDF document content. The PrintHelper takes advantage of the Pageable and Printable interfaces availabe in Java 2.

Since:
2.0

Field Summary
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PrintHelper(DocumentViewController viewController, PageTree pageTree)
          Creates a new PrintHelper instance.
PrintHelper(SwingController controller)
          Creates a new PrintHelper instance.
 
Method Summary
 int getCurrentPage()
          Gets the page number of the page currently being spooled by the Printable interface.
 int getNumberOfPages()
          Gets the number of pages that have been selected for printing.
 PageFormat getPageFormat(int pageIndex)
          Returns the PageFormat of the page specified by pageIndex.
 Printable getPrintable(int pageIndex)
          Returns the Printable instance responsible for rendering the page specified by pageIndex.
 int print(Graphics printGraphics, PageFormat pageFormat, int pageIndex)
          Prints the page at the specified index into the specified java.awt.Graphics context in the specified format.
 void print(PrinterJob printerJob, int startPage, int endPage, int copies, boolean shrinkToPrintableArea, boolean showPageSetupDialog, boolean showPrintDialog, PageFormat docPageFormat)
          Print a range of pages from the document.
 boolean setupPrintJob(PrinterJob printerJob, int startPage, int endPage, int copies, boolean shrinkToPrintableArea, boolean showPageSetupDialog, boolean showPrintDialog, PageFormat docPageFormat)
          Configures the PrinterJob instance with the specified parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintHelper

public PrintHelper(DocumentViewController viewController,
                   PageTree pageTree)
Creates a new PrintHelper instance.

Parameters:
viewController -
pageTree -

PrintHelper

public PrintHelper(SwingController controller)
Creates a new PrintHelper instance.

Parameters:
controller -
Method Detail

getNumberOfPages

public int getNumberOfPages()
Gets the number of pages that have been selected for printing. Do to limitations in the PrinterJob class, it is not possible to detect if a range of pages was selected in the print dialog. If a range has been selected this method will only return the total number of pages in the document and not that of the print range.

Specified by:
getNumberOfPages in interface Pageable
Returns:
Number of pages that have been selected for printing.

getCurrentPage

public int getCurrentPage()
Gets the page number of the page currently being spooled by the Printable interface.

Returns:
current page being spooled by printer.

setupPrintJob

public boolean setupPrintJob(PrinterJob printerJob,
                             int startPage,
                             int endPage,
                             int copies,
                             boolean shrinkToPrintableArea,
                             boolean showPageSetupDialog,
                             boolean showPrintDialog,
                             PageFormat docPageFormat)
Configures the PrinterJob instance with the specified parameters. This method is only needed if you are using the SwingController and PrinterTask to print in a background process, otherwise you should use the print(java.awt.print.PrinterJob, int, int, int, boolean, boolean, boolean, java.awt.print.PageFormat) method.

Parameters:
printerJob - printer job that controls printing. If null, a default printer job will be created.
startPage - start of page range, zero-based index.
endPage - end of page range, zero-based index.
copies - number of copies of pages in print range.
shrinkToPrintableArea - true, to enable shrink to fit printable area; false, otherwise.
showPageSetupDialog - true, to display a page setup dialog when this method is initiated; false, otherwise. This dialog will be shown before the print dialog.
showPrintDialog - true, to display a print setup dialog when this method is initiated; false, otherwise. This dialog will be shown after the page dialog if it is visible.
docPageFormat - Page Format to be associated with print job. If null, a default Page Format will be created.

print

public int print(Graphics printGraphics,
                 PageFormat pageFormat,
                 int pageIndex)
Prints the page at the specified index into the specified java.awt.Graphics context in the specified format.

Specified by:
print in interface Printable
Parameters:
printGraphics -
pageFormat -
pageIndex -
Returns:
A status code of Printable.NO_SUCH_PAGE or Printable.PAGE_EXISTS

getPrintable

public Printable getPrintable(int pageIndex)
Returns the Printable instance responsible for rendering the page specified by pageIndex.

Specified by:
getPrintable in interface Pageable
Parameters:
pageIndex -
Returns:
The Printable object for the specified page, which is this PrintHelper

getPageFormat

public PageFormat getPageFormat(int pageIndex)
Returns the PageFormat of the page specified by pageIndex.

Specified by:
getPageFormat in interface Pageable
Parameters:
pageIndex -
Returns:
The PageFormat object for the specified page

print

public void print(PrinterJob printerJob,
                  int startPage,
                  int endPage,
                  int copies,
                  boolean shrinkToPrintableArea,
                  boolean showPageSetupDialog,
                  boolean showPrintDialog,
                  PageFormat docPageFormat)
Print a range of pages from the document.

Parameters:
printerJob - printer job that controls printing. If null, a default printer job will be created.
startPage - start of page range, zero-based index.
endPage - end of page range, zero-based index.
copies - number of copies of pages in print range.
shrinkToPrintableArea - true, to enable shrink to fit printable area; false, otherwise.
showPageSetupDialog - true, to display a page setup dialog when this method is initiated; false, otherwise. This dialog will be shown before the print dialog.
showPrintDialog - true, to display a print setup dialog when this method is initiated; false, otherwise. This dialog will be shown after the page dialog if it is visible.
docPageFormat - Page Format to be associated with print job. If null, a default Page Format will be created.