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

When printing to XPS or PDF document in landscape orientation, all pages are rotated to portrait

XMLWordPrintable

    • 2d
    • generic
    • generic

      FULL PRODUCT VERSION :
      Tested with JDK 1.8 update 151
      Tested with JDK 1.9 update 1

      A DESCRIPTION OF THE PROBLEM :
      When using Print API with LANDSCAPE orientation specified and printing to XPS Document or PDF Document, all pages of the generated document are well printed in landscape mode but they are all rotated to portrait mode.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Show Print Dialog.
      Select Microsoft XPS Document Writer or Mircrosoft print to PDF.
      Select Landscape orientation.
      Call Print with a printable object.
      Choose destination file.
      Open generated file.

      Or

      Manually select XPS printer
      Create a PageFormat with LANDSCAPE orientation.
      Call Print with a printable object using the PageFormat created.
      Choose destination file.
      Open generated file.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All pages of XPS or PDF Document should stay in landscape orientation.
      ACTUAL -
      All pages of XPS or PDF Document are rotated to portrait orientation (but with results printed in landscape orientation)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.print.PageFormat;
      import java.awt.print.Paper;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;

      import javax.print.PrintService;
      import javax.print.PrintServiceLookup;

      public class LandscapeTest implements Printable {
      public static void main(String[] args) {
      new LandscapeTest();
      }

      public LandscapeTest() {
      testDialog();
      testManual();
      }

      void testDialog() {
      try {
      PrinterJob printer = PrinterJob.getPrinterJob();
      printer.setJobName("LandscapeTest.testDialog");
      printer.setPrintable(this);
      if(printer.printDialog())
      printer.print();
      } catch(Exception e) {
      e.printStackTrace();
      }
      }

      void testManual() {
      try {
      PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
      for(PrintService service : services) {
      if(service.getName().indexOf("XPS") != -1) {
      PrinterJob printer = PrinterJob.getPrinterJob();
      printer.setPrintService(service);
      printer.setJobName("LandscapeTest.testManual");

      PageFormat pg = new PageFormat();
      Paper p = new Paper();
      p.setSize(500, 710);
      p.setImageableArea(0,0,500,710);
      pg.setPaper(p);
      pg.setOrientation(PageFormat.LANDSCAPE);

      printer.setPrintable(this, pg);
      printer.print();
      }
      }
      } catch(Exception e) {
      e.printStackTrace();
      }
      }

      @Override
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
      if(pageIndex == 1)
      return Printable.NO_SUCH_PAGE;

      graphics.setColor(Color.RED);
      graphics.setFont(new Font("Arial", Font.BOLD, 18));
      graphics.drawString("Test Landscape Orientation", 50, 50);
      return Printable.PAGE_EXISTS;
      }
      }

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

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: