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

PrintJob.getPageDimension() will return different values for different JVM's

    XMLWordPrintable

Details

    • x86
    • windows_2000

    Description

      In the IBM JVM and Microsoft JVM a call to PrintJob.getPageDimension() returns the dimensions of the printable printer area.
                                                                                  
      In the SUN JVM this call returns the dimensions of the form size. Since the
      form size does not always equal the printable area, formatting printer output
      to the formsize dimensions can lead to print output being truncated when the
      formsize is larger then the printable area.

      The following test program gives the following values:

      Solaris 2 SDK 1.2.2_07 = > Produces the following:
      build{jnicker}62: java PrintJobSample
      Page Dimension:java.awt.Dimension[width=595,height=842] Resolution:72
      PrintJob is null

      Java 2 SDK v 1.2.2_007 Windows 95/98/2000/NT => Produces the following:
      java PrintJobSample
      Page Dimension:java.awt.Dimension[width=612,height=792] Resolution:72
      PrintJob is null

      The following test code will show the problem:


      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;


      public class PrintJobSample extends Frame implements WindowListener, ActionListener {
          public static void main(String[] args) {
              PrintJobSample ps = new PrintJobSample();
          }

          public PrintJobSample() {
              super(program_name);

              this.setLayout(new FlowLayout());
              this.addWindowListener(this);

              button = new Button(button_label);
              add(button);

              button.addActionListener(this);

              this.setSize(400,60);
              this.show();
          }

          public void actionPerformed(ActionEvent e) {
              String s = e.getActionCommand();
              doPrint();
          }

          private void doPrint() {
              PrintJob pj = this.getToolkit().getPrintJob(this, program_name, null);
              if (pj != null) {
                  Dimension d = pj.getPageDimension();
                  int res = pj.getPageResolution();
                  System.out.println("Page Dimension:"+d+" Resolution:"+res);

                  Graphics g = pj.getGraphics();

                  g.setColor(Color.black);
                  g.drawRect(0, 0, d.width-1, d.height-1);
                  g.drawLine(0, 0, d.width-1, d.height-1);
                  g.drawLine(0, d.height-1, d.width-1, 0);

                  Font f = new Font("Monospaced", Font.PLAIN, 10);
                  g.setFont(f);

                  FontMetrics fm = getFontMetrics(f);
                  int font_height = fm.getHeight();

                  g.drawString(sample_text0, 0, font_height );
                  g.drawString(sample_text1, 0, font_height * 2);
                  g.drawString(sample_text2, 0, font_height * 3);
                  g.drawString(sample_text3, 0, font_height * 4);
                  g.drawString(sample_text4, 0, font_height * 5);

                  pj.end();
              }
              else {
                  System.err.println("PrintJob is null");
              }
          }

          public void windowClosing(WindowEvent e) {
              this.dispose();
              System.exit(0);
          }
          public void windowOpened(WindowEvent e) {}
          public void windowClosed(WindowEvent e) {}
          public void windowIconified(WindowEvent e) {}
          public void windowDeiconified(WindowEvent e) {}
          public void windowActivated(WindowEvent e) {}
          public void windowDeactivated(WindowEvent e) {}

          Button button;
          private static String program_name = "Print Sample";
          private static String button_label = "Print";

          private static String sample_text0 = "0123456789012345678901234567890123456789";
          private static String sample_text1 = "1234567890123456789012345678901234567890";
          private static String sample_text2 = "2345678901234567890123456789012345678901";
          private static String sample_text3 = "3456789012345678901234567890123456789012";
          private static String sample_text4 = "4567890123456789012345678901234567890123";
      }




                                                                                                              
                                                                                  


      Attachments

        Activity

          People

            abhalesunw Ajit Bhale (Inactive)
            jnickers Jeffrey Nickerson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: