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

[macosx] Print to file prints on printer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 9
    • 7u17, 8, 9
    • client-libs
    • 2d
    • os_x

      FULL PRODUCT VERSION :
      java version " 1.7.0_17 "

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.6.8
      Mac OS X 10.8.3


      A DESCRIPTION OF THE PROBLEM :
      Open a print dialog, click the " Print to file " check box.

      Then choose a file and click OK.

      The file not saved on a file but sent to a printer.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the sample program.
      2. Write something in the text pane.
      3. Click the Print button.
      4. Check " Print To File " .
      5. Click on Print.
      6. Select the destination directory in the file chooser.
      7. Click OK.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The file provided to the file chooser should be created with the text pane contents.
      ACTUAL -
      The expected file is not generated, but the text is sent to the printer.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.print.PrinterException;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextPane;
      import javax.swing.SwingUtilities;

      public class TestPrint {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override public void run() {
                      final JTextPane textPane = new JTextPane();
                      JButton button = new JButton( " Print " );
                      button.addActionListener(new ActionListener() {
                          @Override public void actionPerformed(ActionEvent event) {
                              try {
                                  textPane.print();
                              } catch (PrinterException e) {
                                  e.printStackTrace();
                              }
                          }
                      });
                      JFrame frame = new JFrame( " Print Test " );
                      JPanel panel = new JPanel(new BorderLayout(5, 5));
                      panel.add(textPane, BorderLayout.CENTER);
                      panel.add(button , BorderLayout.SOUTH);
                      frame.setContentPane(panel);
                      frame.setSize(600, 450);
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.setLocationRelativeTo(null);
                      frame.setVisible(true);
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The JDK on Mac uses the class apple.awt.CPrinterJob as PrinterJob implementation. This class produces the reported behaviour.

      Setting the property

      java.awt.printerjob=sun.print.PSPrinterJob

      does the right thing.

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: