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

Pages incorrectly flipped on long edge when printing in duplex mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6u10
    • client-libs
    • 2d
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

      java version "1.5.0_14"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Tested on printers HP2430 and HP4200.

      A DESCRIPTION OF THE PROBLEM :
      When printing double-sided, the page is always flipped along the long edge, unless the print dialog is shown and portrait orientation is selected. The behaviour is incorrect for each of the following combinations of print options:

      OrientationRequested.LANDSCAPE
      Sides.TWO_SIDED_SHORT_EDGE

      OrientationRequested.REVERSE_LANDSCAPE
      Sides.TWO_SIDED_SHORT_EDGE

      OrientationRequested.PORTRAIT
      Sides.TWO_SIDED_SHORT_EDGE

      OrientationRequested.REVERSE_PORTRAIT
      Sides.TWO_SIDED_SHORT_EDGE



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      There are several ways to reproduce this problem using the source code provided:

      Method A

      1. Select a printer that supports double-sided printing.
      2. Select Short Edge.
      3. Select Landscape.
      4. Ensure that "Show Print Dialog" is not checked.
      5. Click Print.
      6. Inspect the printed page. The text is flipped along the long edge, not the short edge.

      Method B:
      1. Select a printer that supports double-sided printing.
      2. Select Short Edge.
      3. Select Reverse Landscape.
      4. Ensure that "Show Print Dialog" is not checked.
      5. Click Print.
      6. Inspect the printed page. The text is printed upside down relative to the previous test, but is still flipped along the long edge, not the short edge.

      Method C:

      1. Select a printer that supports double-sided printing.
      2. Ensure that "Show Print Dialog" is checked.
      3. Click Print.
      4. On the Print Options dialog, click Properties.
      5. On the native print options dialog, select double-sided printing.
      6. On the native print options dialog, select landscape orientation.
      7. On the native print options dialog, ensure that the option to flip pages along the short edge is selected.
      8. Click OK to close the native print options dialog.
      9. Click OK to print the document.
      10. Inspect the printed page. The text is flipped along the long edge, not the short edge.

      Method D

      1. Select a printer that supports double-sided printing.
      2. Select Short Edge.
      3. Select Portrait.
      4. Ensure that "Show Print Dialog" is not checked.
      5. Click Print.
      6. Inspect the printed page. The text is flipped along the long edge, not the short edge.

      Method E

      1. Select a printer that supports double-sided printing.
      2. Select Short Edge.
      3. Select Reverse Portrait
      4. Ensure that "Show Print Dialog" is not checked.
      5. Click Print.
      6. Inspect the printed page. The text is flipped along the long edge, not the short edge.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The page should have been flipped along the short edge.

      ACTUAL -
      The page is flipped along the long edge.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error messages or exceptions are reported. No log files are produced.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.print.*;
      import javax.print.*;
      import javax.print.attribute.*;
      import javax.print.attribute.standard.*;
      import java.util.*;
      import java.util.List;
      import javax.swing.*;

      public class FlipTest implements Printable, ActionListener {

      private static Map<String, PrintService> printServices = new TreeMap<String, PrintService>();
      private static JRadioButton btnPortrait = new JRadioButton("Portrait");
      private static JRadioButton btnLandscape = new JRadioButton("Landscape");
      private static JRadioButton btnRevPortrait = new JRadioButton("Reverse Portrait");
      private static JRadioButton btnRevLandscape = new JRadioButton("Reverse Landscape");
      private static JRadioButton btnLongEdge = new JRadioButton("Long Edge");
      private static JRadioButton btnShortEdge = new JRadioButton("Short Edge");
      private static JCheckBox chkShowDialog = new JCheckBox("Show Print Dialog");
      private static JComboBox cboPrinter = new JComboBox();
      private static OrientationRequested orientation = OrientationRequested.PORTRAIT;
      private static Sides flip = Sides.TWO_SIDED_LONG_EDGE;
      private static boolean showDialog = false;

          public int print(Graphics g, PageFormat pf, int page) throws PrinterException {

              if (page > 1) { // zero-based -> print two pages
                  return NO_SUCH_PAGE;
              }

              Graphics2D g2d = (Graphics2D)g;
              g2d.translate(pf.getImageableX(), pf.getImageableY());
              g.setFont(new Font("monospaced", Font.PLAIN, 14));

              g.drawString("Printer Orientation and Flip Test", 100, 50);

              g.drawString("Page: " + (page + 1), 100, 200);

              if (showDialog) {
      g.drawString("Print dialog shown", 100, 300);
      }
      else {
      g.drawString("Orientation: " + orientation, 100, 300);
      g.drawString("Flip: " + flip, 100, 400);
      }

              /* tell the caller that this page is part of the printed document */
              return PAGE_EXISTS;
          }

          public void actionPerformed(ActionEvent e) {
      PrintService service = printServices.get(cboPrinter.getSelectedItem());
      orientation = btnPortrait.isSelected() ? OrientationRequested.PORTRAIT
      : btnLandscape.isSelected() ? OrientationRequested.LANDSCAPE
      : btnRevPortrait.isSelected() ? OrientationRequested.REVERSE_PORTRAIT
      : btnRevLandscape.isSelected() ? OrientationRequested.REVERSE_LANDSCAPE
      : OrientationRequested.PORTRAIT;

      flip = btnLongEdge.isSelected() ? Sides.TWO_SIDED_LONG_EDGE
      : btnShortEdge.isSelected() ? Sides.TWO_SIDED_SHORT_EDGE
      : Sides.ONE_SIDED;

      showDialog = chkShowDialog.isSelected();

      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintable(this);

      // Set print options
      PrintServiceAttributeSet svcAttribs = service.getAttributes();
      PrintRequestAttributeSet reqAttribs = new HashPrintRequestAttributeSet();

      reqAttribs.add(orientation);
      reqAttribs.add(flip);
      reqAttribs.add(Fidelity.FIDELITY_TRUE);

      try {
      job.setPrintService(service);
      } catch (PrinterException ex) {
      ex.printStackTrace();
      }

      if (showDialog) {
      // Let the user select print options.
      boolean ok = job.printDialog(); // show the native dialog
      // boolean ok = job.printDialog(reqAttribs); // show the Java dialog
      if (ok) {
      try {
      job.print();
      } catch (PrinterException ex) {
      // The job did not successfully complete
      ex.printStackTrace();
      }
      }
      }
      else {
      try {
      job.print(reqAttribs);
      } catch (PrinterException ex) {
      ex.printStackTrace();
      }
      }
          }

          private static String[] getPrinters() {
      printServices.clear();
      PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
      for (PrintService service : services) {
      String name = service.getName();
      printServices.put(name, service);
      }
      return printServices.keySet().toArray(new String[0]);
      }

          public static void main(String args[]) {

              UIManager.put("swing.boldMetal", Boolean.FALSE);
              JFrame f = new JFrame("Printer Orientation and Flip Test");
              f.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {System.exit(0);}
              });
              f.setLayout(new GridLayout(5, 2));

              ButtonGroup btnGrpOrient = new ButtonGroup();
              btnGrpOrient.add(btnPortrait);
              btnGrpOrient.add(btnLandscape);
              btnGrpOrient.add(btnRevPortrait);
              btnGrpOrient.add(btnRevLandscape);
              btnPortrait.setSelected(true);

              ButtonGroup btnGrpSides = new ButtonGroup();
              btnGrpSides.add(btnLongEdge);
              btnGrpSides.add(btnShortEdge);
              btnLongEdge.setSelected(true);

              chkShowDialog = new JCheckBox("Show Print Dialog");

              for (String printer : getPrinters()) {
      cboPrinter.addItem(printer);
      }

              JButton printButton = new JButton("Print");
              printButton.addActionListener(new FlipTest());

              f.add(cboPrinter);
              f.add(chkShowDialog);
              f.add(btnPortrait);
              f.add(btnLongEdge);
              f.add(btnLandscape);
              f.add(btnShortEdge);
              f.add(btnRevPortrait);
              f.add(printButton);
              f.add(btnRevLandscape);

              f.pack();
              f.setVisible(true);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use the print option Sides.TWO_SIDED_LONG_EDGE.

      Implement a Pageable that produces different PrintFormats for alternating pages. To print with landscape orientation, it should alternately select LANDSCAPE and REVERSE_LANDSCAPE orientation. To print with portrait orientation, it should alternately select PORTRAIT and REVERSE_PORTRAIT orientation.

      Rotating alternate pages in this fashion has the same effect as flipping them along the opposite edge. Unfortunately, not all printers support the reverse orientation options. For example, the HP2430 printer does not support REVERSE_PORTRAIT orientation. Finishing options such as staples might also be applied to the wrong edge or corner of the page.

            psadhukhan Prasanta Sadhukhan
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: