Class PrintHelper

    • Field Detail

      • EMPTY_PRINTSERVICE_ARRAY

        public static final PrintService[] EMPTY_PRINTSERVICE_ARRAY
      • CLIPPING_FIX_ENABLED

        protected static final boolean CLIPPING_FIX_ENABLED
    • Method Detail

      • preloadServices

        public static void preloadServices()
      • reloadServices

        public static void reloadServices()
      • 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.
      • print

        public abstract void print()
                            throws PrintException
        Print 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.
      • 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.
      • 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.