- java.lang.Object
-
- org.icepdf.ri.common.print.PrintHelper
-
- All Implemented Interfaces:
Printable
- Direct Known Subclasses:
PrintHelperImpl
public abstract class PrintHelper extends Object implements Printable
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanCLIPPING_FIX_ENABLEDstatic PrintService[]EMPTY_PRINTSERVICE_ARRAYstatic StringPRINTER_NAME_ATTRIBUTE-
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPrintHelper(DocAttributeSet docAttributeSet, PrintRequestAttributeSet printRequestAttributeSet)protectedPrintHelper(PrintQuality printQuality, MediaSizeName paperSizeName)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract CancelablePrintJobcancelablePrint()protected static DocAttributeSetcreateDocAttributeSet(MediaSizeName paperSizeName)protected static PrintRequestAttributeSetcreatePrintRequestAttributeSet(PrintQuality printQuality, MediaSizeName paperSizeName)intgetCurrentPage()Gets the page number of the page currently being spooled by the Printable interface.DocAttributeSetgetDocAttributeSet()Gets the document attributes currently in use.intgetNumberOfPages()Number of total pages being printed.PrintRequestAttributeSetgetPrintRequestAttributeSet()Gets the print request attribute sets.PrintServicegetPrintService()PrintServicegetPrintServiceOrDefault()Gets the currently assigned print service, or gets the default print service.static PrintService[]getServices()protected abstract PrintServicegetSetupDialog()Utility for creating a print setup dialog.static MediaSizeNameguessMediaSizeName(Document document)Returns the MediaSizeName corresponding to the first page in a documentstatic booleanhasPrinter(String printer)Checks that the given printer existsbooleanisPaintAnnotation()Are page annotations going to be printed?booleanisPaintSearchHighlight()Are page search highlight's going to be printed?booleanisPrintFitToMargin()Gets the fit to margin property.protected static PrintService[]lookForPrintServices()static voidpreloadServices()abstract voidprint()Print a range of pages from the document as specified by #setupPrintService.abstract intprint(Graphics graphics, PageFormat pageFormat, int i)abstract voidprint(PrintJobWatcher printJobWatcher)static voidreloadServices()protected voidsetCurrentPage(int currentPage)protected voidsetDocAttributeSet(DocAttributeSet docAttributeSet)protected voidsetNumberOfPages(int numberOfPages)voidsetPaintAnnotation(boolean paintAnnotation)Manually enable or disable the printing of annotation for a print jobvoidsetPaintSearchHighlight(boolean paintSearchHighlight)Manually enable or disable the printing of search highlights for a print jobvoidsetPrinter(String name)Sets the printer defined by the given name as current oneprotected voidsetPrintFitToMargin(boolean fitToMargin)protected voidsetPrintRequestAttributeSet(PrintRequestAttributeSet printRequestAttributeSet)protected voidsetPrintService(PrintService printService)booleansetupPrintService(int startPage, int endPage, int copies, boolean shrinkToPrintableArea, boolean showPrintDialog)Configures the PrinterJob instance with the specified parameters.voidsetupPrintService(PrintService printService, int startPage, int endPage, int copies, boolean shrinkToPrintableArea)Configures the PrinterJob instance with the specified parameters.voidsetupPrintService(PrintService printService, PrintRequestAttributeSet printRequestAttributeSet, boolean shrinkToPrintableArea)Configures the PrinterJob instance with the specified parameters.abstract voidshowPrintSetupDialog()Utility for showing print dialog for the current printService.
-
-
-
Field Detail
-
EMPTY_PRINTSERVICE_ARRAY
public static final PrintService[] EMPTY_PRINTSERVICE_ARRAY
-
PRINTER_NAME_ATTRIBUTE
public static final String PRINTER_NAME_ATTRIBUTE
- See Also:
- Constant Field Values
-
CLIPPING_FIX_ENABLED
protected static final boolean CLIPPING_FIX_ENABLED
-
-
Constructor Detail
-
PrintHelper
protected PrintHelper(DocAttributeSet docAttributeSet, PrintRequestAttributeSet printRequestAttributeSet)
-
PrintHelper
protected PrintHelper(PrintQuality printQuality, MediaSizeName paperSizeName)
-
-
Method Detail
-
preloadServices
public static void preloadServices()
-
reloadServices
public static void reloadServices()
-
createDocAttributeSet
protected static DocAttributeSet createDocAttributeSet(MediaSizeName paperSizeName)
-
createPrintRequestAttributeSet
protected static PrintRequestAttributeSet createPrintRequestAttributeSet(PrintQuality printQuality, MediaSizeName paperSizeName)
-
getNumberOfPages
public int getNumberOfPages()
Number of total pages being printed.- Returns:
- total pages being printed.
-
setNumberOfPages
protected void setNumberOfPages(int numberOfPages)
-
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.
-
setCurrentPage
protected void setCurrentPage(int currentPage)
-
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.
-
setPrintFitToMargin
protected void setPrintFitToMargin(boolean fitToMargin)
-
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.
-
showPrintSetupDialog
public abstract 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.
-
setupPrintService
public void setupPrintService(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 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(PrintService printService, PrintRequestAttributeSet 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 job attribute set.shrinkToPrintableArea- true, to enable shrink to fit printable area; false, otherwise.
-
cancelablePrint
public abstract CancelablePrintJob cancelablePrint() throws PrintException
- Throws:
PrintException
-
print
public abstract void print(PrintJobWatcher printJobWatcher) throws PrintException
- Throws:
PrintException
-
print
public abstract int print(Graphics graphics, PageFormat pageFormat, int i) throws PrinterException
- Specified by:
printin interfacePrintable- Throws:
PrinterException
-
print
public abstract void print() throws PrintExceptionPrint a range of pages from the document as specified by #setupPrintService.- Throws:
PrintException- if a default printer could not be found or some other printing related error.
-
getServices
public static PrintService[] getServices()
-
getDocAttributeSet
public DocAttributeSet getDocAttributeSet()
Gets the document attributes currently in use.- Returns:
- current document attributes.
-
setDocAttributeSet
protected void setDocAttributeSet(DocAttributeSet docAttributeSet)
-
getPrintRequestAttributeSet
public PrintRequestAttributeSet getPrintRequestAttributeSet()
Gets the print request attribute sets.- Returns:
- attribute set
-
setPrintRequestAttributeSet
protected void setPrintRequestAttributeSet(PrintRequestAttributeSet printRequestAttributeSet)
-
getPrintServiceOrDefault
public PrintService getPrintServiceOrDefault()
Gets the currently assigned print service, or gets the default print service.- Returns:
- current print service, can be null.
-
getPrintService
public PrintService getPrintService()
-
setPrintService
protected void setPrintService(PrintService printService)
-
guessMediaSizeName
public static MediaSizeName guessMediaSizeName(Document document)
Returns the MediaSizeName corresponding to the first page in a document- Parameters:
document- The document- Returns:
- The MediaSizeName if found, A4 by default
-
hasPrinter
public static boolean hasPrinter(String printer)
Checks that the given printer exists- Parameters:
printer- The printer name- Returns:
- True if it exists or printer equals 'default'
-
setPrinter
public void setPrinter(String name)
Sets the printer defined by the given name as current one- Parameters:
name- The name of the printer
-
lookForPrintServices
protected static PrintService[] lookForPrintServices()
-
getSetupDialog
protected abstract PrintService getSetupDialog()
Utility for creating a print setup dialog.- Returns:
- print service selected by the user, or null if the user cancelled the dialog.
-
-