Class PrintHelperImpl

  • All Implemented Interfaces:
    Printable

    public class PrintHelperImpl
    extends PrintHelper

    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
    • Constructor Detail

      • PrintHelperImpl

        public PrintHelperImpl​(Container container,
                               PageTree pageTree,
                               float rotation,
                               MediaSizeName paperSizeName,
                               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.
      • PrintHelperImpl

        public PrintHelperImpl​(Container container,
                               PageTree pageTree,
                               float userRotation,
                               DocAttributeSet docAttributeSet,
                               PrintRequestAttributeSet 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

      • showPrintSetupDialog

        public void showPrintSetupDialog()
        Description copied from class: PrintHelper
        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.
        Specified by:
        showPrintSetupDialog in class PrintHelper
      • getUserRotation

        public float getUserRotation()
        Users rotation specified for the print job.
        Returns:
        float value representing rotation, 0 is 0 degrees.
      • 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
        Specified by:
        print in class PrintHelper
        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 PrintException
        Description copied from class: PrintHelper
        Print a range of pages from the document as specified by #setupPrintService.
        Specified by:
        print in class PrintHelper
        Throws:
        PrintException - if a default printer could not be found or some other printing related error.
      • getSetupDialog

        protected PrintService getSetupDialog()
        Description copied from class: PrintHelper
        Utility for creating a print setup dialog.
        Specified by:
        getSetupDialog in class PrintHelper
        Returns:
        print service selected by the user, or null if the user cancelled the dialog.