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

Print to file using cross-platform printDialog does not work.

XMLWordPrintable

    • 2d
    • beta3
    • generic
    • windows_nt

      Clicking on Print to File button still prints the output to the printer. It fails on Win32 only.

      import java.awt.*;
      import java.awt.print.*;
      import javax.print.attribute.HashPrintRequestAttributeSet;

      public class CrossDialog {
          public static void main(String args[]) {
          PrinterJob pj = PrinterJob.getPrinterJob();
          HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
          if (pj != null && pj.printDialog(aset)) {
              pj.setPrintable(new Printable() {
              public int print(Graphics g, PageFormat pf, int pgIndex) {
                  if (pgIndex > 0) {
                  return Printable.NO_SUCH_PAGE;
                  }
                  g.drawString("Printed!", (int)pf.getImageableX() + 50, (int)pf.getIm
      ageableY() + 50);
                  return Printable.PAGE_EXISTS;
              }
              });
              try {
              pj.print(aset);
              } catch (PrinterException pe) {
              } finally {
              }
          }
             System.exit(0);
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: