0 Replies Latest reply on Dec 30, 2008 5:21 PM by 843804

    Java Printing Problem after upgrade from Java 1.4 to Java 1.6.0_05

    843804
      Hi All,

      My application uses the Java Printing API (java.awt.print packages) to print an image along with some text to the selected printer. When the client was runninig on JDK 1.4, the PrintJob.printDialog() method would show the print dialog with defaults as Portrait and 1.0 margins all the way around. The same code, after migrating to JDK 1.6 shows Landscape and 1.75 in margins for left and bottom and 0.25 in margins for right and top. This is messing up the printing of the image when I try to print. I tried to change the margins manually, but it keeps reverting back to its defaults (1.75).

      I am running a swing client on Linux with JDK 1.6.0_05.
      Here is the code for the print job:
      public void run() 
      {
      
      PrinterJob pj = PrinterJob.getPrinterJob();
      // PageFormat pf = pj.defaultPage();
      PageFormat pf = new PageFormat();
      Paper paper = new Paper();
      double margin = 36; // 1/2 inch
      paper.setImageableArea( margin, margin * .75, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2 );
      pf.setPaper( paper );
      pf.setOrientation( PageFormat.LANDSCAPE );
      pj.setPrintable( this, pf );
      
      if ( pj.printDialog() )
      {
      try
      {
      pj.print();
      }
      catch ( PrinterException e )
      {
      e.printStackTrace();
      }
      }
      
      }
      
      
      
      
      
      public int print( Graphics g, PageFormat pf, int pageIndex )
      {
      if ( pageIndex > 0 )
      return NO_SUCH_PAGE;
      if ( isLargePrint )
      printEnlarged( g, pf );
      else
      printNormal( g, pf );
      
      return PAGE_EXISTS;
      }
      Any help would be greatly appreciated.

      Prashanth