org.icepdf.ri.common
Class PrintHelper

java.lang.Object
  extended by org.icepdf.ri.common.PrintHelper
All Implemented Interfaces:
java.awt.print.Printable

public class PrintHelper
extends java.lang.Object
implements java.awt.print.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.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PrintHelper(java.awt.Container container, org.icepdf.core.pobjects.PageTree pageTree, float userRotation, javax.print.attribute.HashDocAttributeSet docAttributeSet, javax.print.attribute.HashPrintRequestAttributeSet printRequestAttributeSet)
          Creates a new PrintHelper instance using the specified doc and print attribute sets.
PrintHelper(java.awt.Container container, org.icepdf.core.pobjects.PageTree pageTree, float rotation, javax.print.attribute.standard.MediaSizeName paperSizeName, javax.print.attribute.standard.PrintQuality printQuality)
          Creates a new PrintHelper instance using the specified media sized and print quality.
PrintHelper(java.awt.Container container, org.icepdf.core.pobjects.PageTree pageTree, int rotation)
          Creates a new PrintHelper instance defaulting the paper size to Letter and the print quality to Draft.
 
Method Summary
 javax.print.CancelablePrintJob cancelablePrint()
           
 int getCurrentPage()
          Gets the page number of the page currently being spooled by the Printable interface.
 javax.print.attribute.HashDocAttributeSet getDocAttributeSet()
          Gets the document attributes currently in use.
 int getNumberOfPages()
          Number of total pages being printed.
 javax.print.attribute.HashPrintRequestAttributeSet getPrintRequestAttributeSet()
          Gets the print request attribute sets.
 javax.print.PrintService getPrintService()
          Gets the currently assigned print service.
 float getUserRotation()
          Users rotation specified for the print job.
 boolean isPaintAnnotation()
          Are page annotations going to be printed?
 boolean isPaintSearchHighlight()
          Are page search highlight's going to be printed?
 boolean isPrintFitToMargin()
          Gets the fit to margin property.
 void print()
          Print a range of pages from the document as specified by #setupPrintService.
 int print(java.awt.Graphics printGraphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Prints the page at the specified index into the specified java.awt.Graphics context in the specified format.
 void print(PrintJobWatcher printJobWatcher)
           
 void setPaintAnnotation(boolean paintAnnotation)
          Manually enable or disable the printing of annotation for a print job
 void setPaintSearchHighlight(boolean paintSearchHighlight)
          Manually enable or disable the printing of search highlights for a print job
 boolean setupPrintService(int startPage, int endPage, int copies, boolean shrinkToPrintableArea, boolean showPrintDialog)
          Configures the PrinterJob instance with the specified parameters.
 void setupPrintService(javax.print.PrintService printService, javax.print.attribute.HashPrintRequestAttributeSet printRequestAttributeSet, boolean shrinkToPrintableArea)
          Configures the PrinterJob instance with the specified parameters.
 void setupPrintService(javax.print.PrintService printService, int startPage, int endPage, int copies, boolean shrinkToPrintableArea)
          Configures the PrinterJob instance with the specified parameters.
 void showPrintSetupDialog()
          Utility for showing print dialog for the current printService.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintHelper

public PrintHelper(java.awt.Container container,
                   org.icepdf.core.pobjects.PageTree pageTree,
                   int rotation)
Creates a new PrintHelper instance defaulting the paper size to Letter and the print quality to Draft.

Parameters:
container - parent container used to center print dialogs.
pageTree - document page tree.

PrintHelper

public PrintHelper(java.awt.Container container,
                   org.icepdf.core.pobjects.PageTree pageTree,
                   float rotation,
                   javax.print.attribute.standard.MediaSizeName paperSizeName,
                   javax.print.attribute.standard.PrintQuality printQuality)
Creates a new PrintHelper instance using the specified media sized and print quality.

Parameters:
container - parent container uses to center print dialog.
pageTree - document page tree.
rotation - rotation at witch to paint document.
paperSizeName - MediaSizeName constant of paper size to print to.
printQuality - quality of the print job, draft, quality etc.

PrintHelper

public PrintHelper(java.awt.Container container,
                   org.icepdf.core.pobjects.PageTree pageTree,
                   float userRotation,
                   javax.print.attribute.HashDocAttributeSet docAttributeSet,
                   javax.print.attribute.HashPrintRequestAttributeSet printRequestAttributeSet)
Creates a new PrintHelper instance using the specified doc and print attribute sets. This constructor offers the most flexibility as it allows the attributes sets to be pre configured. This method should only be used by advanced users.

Parameters:
container - parent container uses to center print dialog.
pageTree - document page tree.
userRotation - rotation of view
docAttributeSet - MediaSizeName constant of paper size to print to.
printRequestAttributeSet - quality of the print job, draft, quality etc.
Method Detail

setupPrintService

public boolean setupPrintService(int startPage,
                                 int endPage,
                                 int copies,
                                 boolean shrinkToPrintableArea,
                                 boolean showPrintDialog)
Configures the PrinterJob instance with the specified parameters.

Parameters:
startPage - start of page range, zero-based index.
endPage - end of page range, one-based index.
copies - number of copies of pages in print range.
shrinkToPrintableArea - true, to enable shrink to fit printable area; false, otherwise.
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.
Returns:
true if print setup should continue, false if printing was cancelled by user interaction with optional print dialog.

setupPrintService

public void setupPrintService(javax.print.PrintService printService,
                              int startPage,
                              int endPage,
                              int copies,
                              boolean shrinkToPrintableArea)
Configures the PrinterJob instance with the specified parameters.

Parameters:
printService - print service to print document to.
startPage - start of page range, zero-based index.
endPage - end of page range, one-based index.
copies - number of copies of pages in print range.
shrinkToPrintableArea - true, to enable shrink to fit printable area; false, otherwise.

setupPrintService

public void setupPrintService(javax.print.PrintService printService,
                              javax.print.attribute.HashPrintRequestAttributeSet printRequestAttributeSet,
                              boolean shrinkToPrintableArea)
Configures the PrinterJob instance with the specified parameters. this method should only be used by advanced users.

Parameters:
printService - print service to print document to.
printRequestAttributeSet - print jobt attribute set.
shrinkToPrintableArea - true, to enable shrink to fit printable area; false, otherwise.

showPrintSetupDialog

public void showPrintSetupDialog()
Utility for showing print dialog for the current printService. If no print service is assigned the first print service is used to create the print dialog.


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.

getNumberOfPages

public int getNumberOfPages()
Number of total pages being printed.

Returns:
total pages being printed.

isPrintFitToMargin

public boolean isPrintFitToMargin()
Gets the fit to margin property. If enabled the page is scaled to fit the paper size maxing out on the smallest paper dimension.

Returns:
true if fit to margin is enabled.

getUserRotation

public float getUserRotation()
Users rotation specified for the print job.

Returns:
float value representing rotation, 0 is 0 degrees.

getDocAttributeSet

public javax.print.attribute.HashDocAttributeSet getDocAttributeSet()
Gets the document attributes currently in use.

Returns:
current document attributes.

getPrintRequestAttributeSet

public javax.print.attribute.HashPrintRequestAttributeSet getPrintRequestAttributeSet()
Gets the print request attribute sets.

Returns:
attribute set

getPrintService

public javax.print.PrintService getPrintService()
Gets the currently assigned print service.

Returns:
current print service, can be null.

print

public int print(java.awt.Graphics printGraphics,
                 java.awt.print.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 java.awt.print.Printable
Parameters:
printGraphics - paper graphics context.
pageFormat - print attributes translated from PrintService
pageIndex - page to print, zero based.
Returns:
A status code of Printable.NO_SUCH_PAGE or Printable.PAGE_EXISTS

print

public void print()
           throws javax.print.PrintException
Print a range of pages from the document as specified by #setupPrintService.

Throws:
javax.print.PrintException - if a default printer could not be found or some other printing related error.

cancelablePrint

public javax.print.CancelablePrintJob cancelablePrint()
                                               throws javax.print.PrintException
Throws:
javax.print.PrintException

print

public void print(PrintJobWatcher printJobWatcher)
           throws javax.print.PrintException
Throws:
javax.print.PrintException

isPaintAnnotation

public boolean isPaintAnnotation()
Are page annotations going to be printed?

Returns:
true if annotation are to be printed, false otherwise

setPaintAnnotation

public void setPaintAnnotation(boolean paintAnnotation)
Manually enable or disable the printing of annotation for a print job

Parameters:
paintAnnotation - true to paint annotation; otherwise false.

isPaintSearchHighlight

public boolean isPaintSearchHighlight()
Are page search highlight's going to be printed?

Returns:
true if highlights are to be printed, false otherwise

setPaintSearchHighlight

public void setPaintSearchHighlight(boolean paintSearchHighlight)
Manually enable or disable the printing of search highlights for a print job

Parameters:
paintSearchHighlight - true to paint search highlights; otherwise false.