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

[macos] native PrintDialog, Open in Preview prints the document directly

XMLWordPrintable

    • 2d
    • aarch64
    • os_x

      A DESCRIPTION OF THE PROBLEM :
      macOS native print dialog: 'Open in Preview' prints the document instead of open it in Preview application first
      - macOS Big Sur 11.6.1 / macOS Monterey
      - affected jdk versions: OpenJDK 16 and OpenJDK 17.0.1
      - previously worked in OpenJDK 15 and earlier


      REGRESSION : Last worked in version 15

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run attached program
      2. In the Print dialog: Select 'Open in Preview' form button 'PDF' (lower left corner)
      3. The document is printed instead of opened in Preview

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Open document in Preview application
      ACTUAL -
      The document is printed

      ---------- BEGIN SOURCE ----------
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;

      public class Test implements Printable {

          @Override
          public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
              if (pageIndex == 0) {
                  try {
                      final Graphics2D g2d = (Graphics2D)g;
                      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                      final String s = "Java " + System.getProperty("java.version") + " " + System.getProperty("java.vm.name") + " / " + System.getProperty("os.name") + " " + System.getProperty("os.version");
                      g2d.drawString(s, 50, 50);
                  } catch (Exception ex) {
                      throw new PrinterException(ex.getMessage());
                  }
                  return PAGE_EXISTS;
              } else {
                  return NO_SUCH_PAGE;
              }
          }

          public static void main(String[] args) {
              final PrinterJob printerJob = PrinterJob.getPrinterJob();
              printerJob.setPrintable(new Test());
              if (printerJob.printDialog()) {
                  try {
                      printerJob.print();
                  } catch (PrinterException e) {
                      e.printStackTrace();
                  }
              }
          }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: