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

setting orientation does not affect printer

    XMLWordPrintable

Details

    • 2d
    • 1.2.2
    • generic, x86
    • generic, windows_98, windows_nt
    • Verified

    Description



      Name: tb29552 Date: 10/30/98


      /*
      I'm setting a pageformat of landscape.
      However, it doesn't cause the printer
      to print the page in landscape.
      The page contents are in landscape but
      the page is still in portrait.
      here's a sample program.

      */
      /*
      Printing One Page with Graphics

      Note that (0, 0) of the Graphics object is at the top-left of
      the actual page, which is outside the printable area.
      [EDITOR's NOTE: this is bug id 4179886]
      In this example, the Graphics object is translated so that
      (0, 0) becomes the top-left corner of the printable area.
      */

      import java.awt.*;
      import java.awt.print.*;
      import java.awt.geom.*;
      import javax.swing.*;

      //
      public class PrintGraphic extends JComponent implements Printable {
          public int print(Graphics g, PageFormat pf, int pageIndex) {
              if (pageIndex > 0) {
                  return Printable.NO_SUCH_PAGE;
              }
              Graphics2D g2d = (Graphics2D) g;
              g2d.translate(pf.getImageableX(), pf.getImageableY());
               /* i */ drawGraphics(g2d, pf); /**/
              return Printable.PAGE_EXISTS;
          }

      //
          void drawGraphics(Graphics2D g, PageFormat pf) {
              double x, y, iw, w, h, ih;
              System.out.println(x = pf.getImageableX());
              System.out.println(y = pf.getImageableY());
              System.out.println(iw = pf.getImageableWidth());
              System.out.println(ih = pf.getImageableHeight());
              System.out.println(w = pf.getWidth());
              System.out.println(h = pf.getHeight());
              g.setColor(Color.black);
              g.draw(new Ellipse2D.Double(0, 0, iw, ih));
              g.drawString("Hello", 200, 200);
              g.fillOval(0, 0, 100, 100);
          }
      //
          public static void main(String[] args) {
              PrinterJob pjob = PrinterJob.getPrinterJob();
              PageFormat pf = pjob.defaultPage();
              pf.setOrientation(PageFormat.LANDSCAPE);
              pjob.setPrintable(new PrintGraphic (), pf);
              try {
                  pjob.print();
              } catch(Exception e) {
                  e.printStackTrace();
              }
          }
      }
      //

      (Review ID: 41624)
      ======================================================================

      Name: gsC80088 Date: 03/04/99


      When printing to a PostScript printer, your Printable's print method is supplied with either a PSPathGraphics which generates "normal" PostScript or a ProxyGraphics2D which generates a gigantic image of the page. In the PSPathGraphics case, the Graphic2D doesn't have the correct page transform set.

      To repeat:

      1) Make a Printable which does a bit of line drawing.
      2) Print.
      3) Print again, but using a PageFormat with landscape orientation

      In the second case, you'll find that the page won't be rotated correctly.
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mpeircesunw Michael Peirce (Inactive)
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: