Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8023045

[macosx] PrinterIOException when printing a JComponent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 8
    • None
    • client-libs
    • 2d
    • b105
    • os_x
    • Verified

      Code snippet is below:
      ----------
        public static class PrintUtils implements Printable {
          private JComponent componentToBePrinted;
          protected double scale =1.0;
          PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();


          public static void printComponent(JComponent c) {
            new PrintUtils(c).print();
          }

          public PrintUtils(JComponent componentToBePrinted) {
            this.componentToBePrinted = componentToBePrinted;

          }

          void print() {
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
                pras.add(MediaSizeName.NA_LEGAL);

            PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor,pras);
            PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
            if ((defaultService == null) || (printService.length == 0)) {
                System.out.println("No default print service found. Test aborted.");
                return;
            }

            PrintService service = ServiceUI.printDialog(null,100,100,printService,defaultService,flavor,pras);

            if(service != null) {
              DocPrintJob job = service.createPrintJob();
              DocAttributeSet das = new HashDocAttributeSet();

              Doc doc = new SimpleDoc(this,flavor,das);

              try {
                job.print(doc,pras);

              } catch(PrintException pe) {
                pe.printStackTrace();
              }
            }

          }

      -----------------
      OUTPUT:

      javax.print.PrintException: java.awt.print.PrinterIOException
      at sun.print.UnixPrintJob.printableJob(UnixPrintJob.java:653)
      at sun.print.UnixPrintJob.print(UnixPrintJob.java:505)
      at PrintTest$PrintUtils.print(PrintTest.java:144)
      at PrintTest$PrintUtils.printComponent(PrintTest.java:116)
      at PrintTest.jMenuItem1_actionPerformed(PrintTest.java:103)
      at PrintTest$1.actionPerformed(PrintTest.java:53)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

            jgodinez Jennifer Godinez (Inactive)
            jgodinez Jennifer Godinez (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: