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

PrintJob pageDimension and resolution inconsistent

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95, windows_nt

      Description



      Name: joT67522 Date: 12/18/97


      I am using Windows 95 and Java 1.1.5.
      I have an HP LaserJet 4MP,
      which is a 600dpi PostScript printer.
      PrintJob reports a pageResolution of 600
      pixels per inch, a
      pageDimension.width of 612 pixels
      which is 8.5 * 72)
      and a pageDimension.height
      of 792 pixels (which is 11 * 72).
      Since PostScript's
      native coordinate system
      is 72 dpi, it is reasonable to assume that
      getPageDimension is returning
      coordinates based on 72 dpi. Indeed,
      printing works correctly
      if I position graphics objects as if it
      were a 72 dpi printer.

      This is wrong: pageResolution and pageDimension
      should be
      consistent. Either getPageResolution should
      report 72dpi or getPageDimension
      should return numbers consistent with 600 dpi
      (width=8.5*600 and height=11*600).

      While screen-like printer resolutions
      (e.g., 72 dpi) may be sufficient
      and convenient
      for many applications, other applications
      (including mine) need
      access to every pixel. Thus I hope you will
      fix pageDimension
      to give me the full access to my 600 dpi printer.

      I don't know if this is a Java problem or a
      problem with the printer
      driver in Windows, but it is a problem.

      P.S. This is an improvement over Java 1.1.4,
      which gave really odd
      pageDimension values.

      ---

      Enclosed is a small test program. When I run it on Windows 95 with an
      HP LaserJet 4MP (PostScript) printer, the console prints:

      Java: Sun Microsystems Inc. 1.1.5, class 45.3.
      dpi=600 width=612 height=792

      and it prints a one inch square on the printer.

      Again, I hope your solution leads to me getting full access to my 600
      dpi printer (that is, width should be 5100=8.5*600 and height should be
      6600=11*600).

      Also, the bug was sort of fixed. Java 1.1.4 gave really odd
      pageDimension values. At least there is some logic now. Even it I am
      left with a 72 dpi printer.

      /* Start test program *****************************************/
      import java.awt.*;

      public class BobsPrintTest extends Frame {


        //constructor
        public BobsPrintTest() {
          }

        /**
         * This displays the print dialog box, prints printJob values, and
         * prints 72x72 pixel square.
         * <UL>
         * <LI> This returns an error string ("" if no error).
         * </UL>
         */
        public String print() {
          /*12/15/97 Java 1.1.5 is a little better
            For my 4MP it reports 600 dpi (correct),
              width= 612 (which is 8.5" * 72 dpi)
              and height= 792 (which is 11 * 72 dpi)
              Note using printer buttons to select 300dpi still yields
              report of 600 dpi.
            Note using printer buttons to select PCL only still yields
              report of 600, 612, 792 and prints correctly.
          */

          Graphics g=null;
          java.util.Properties printPrefs=new java.util.Properties();

          //call print job dialog
          PrintJob job=Toolkit.getDefaultToolkit().getPrintJob(
            this, "Bob's Print Test", printPrefs);
          if (job==null) return ""; //if user cancelled, return

          try {
            //get and print the pringJob values
            int dpi=job.getPageResolution();
            Dimension pageSize=job.getPageDimension();
            int pageWidth=pageSize.width;
            int pageHeight=pageSize.height;
            System.out.println("dpi="+dpi+
              " width="+pageWidth+
              " height="+pageHeight);

            //get the page's Graphics object
            g=job.getGraphics();
            if (g==null) {
              job.end();
              return "The page graphics object is null!";
              }

            //draw the square
            g.setColor(Color.black);
            g.drawRect(100, 100, 72, 72);
            g.dispose();
            job.end();
            }
          catch (Exception e) {
            if (g!=null) g.dispose();
            job.end();
            return "Unexpected error.";
            }
          return "";

          }


        /**
         * Print some basic test information, create the frame, and run
         * the print test.
         */
        public static void main(String args[]) {
          System.out.println("Java: "+
            System.getProperty("java.vendor")+" "+
            System.getProperty("java.version")+", class "+
            System.getProperty("java.class.version")+".");

          BobsPrintTest test=new BobsPrintTest();
          test.setBounds(0,0, 600, 350);
          test.setVisible(true);
          test.print();
          System.exit(0);

          }

        }
      /* end test program ******************************************/



      (Review ID: 21974)

      ======================================================================
      ###@###.### 1998-01-15

      Another user report similar page dimension problem. Even though the bug
      titled print scale to large, the test case points to the page dimension
      and resolution.

      The PrintJob scale is still not quite fixed.
      While it is larger than before, now it is too
      large for the page. The following code should
      produce a border around the edges of a page:

         Toolkit tk = Toolkit.getDefaultToolkit();
         PrintJob pjob = tk.getPrintJob(null, "Print Test", null);
         Dimension psize = pjob.getPageDimension();
         Graphics pg = pjob.getGraphics();

         pg.drawRect(0, 0, psize.width, psize.height);

         pg.dispose();
         pjob.end();


      The rectangle produced goes off the right and
      bottom edges of the page.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmendenhsunw David Mendenhall (Inactive)
                Reporter:
                johsunw Joon Oh (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: