BUG: PrintJob Output is Incorrect After First Page

Last reviewed: March 17, 1998
Article ID: Q182623
The information in this article applies to:
  • SDK for Java, versions 2.0, 2.01
  • Microsoft Win32 Virtual Machine for Java
  • Microsoft Visual J++, version 1.1

SYMPTOMS

When printing text or graphics from Java using java.awt.PrintJob, the output has different font sizes, line thickness', and other Graphics attributes on different pages even when the same Graphic attributes and fonts are used on all pages.

Also, subsequent pages do not reset the offset from a previous translate() call. For example, if your paint() routine calls gr.translate(10,10), then the first page printed starts at origin (10,10), the second page starts at origin (20,20) and so on.

CAUSE

This problem happens with some printer drivers depending on whether the driver resets state between pages.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce the Font and Graphic Attribute Issue

Create a Java Application and include the following class:

   import java.awt.*;
   import com.ms.ui.*;

   public class PrintFont extends UIFrame
   {
      public PrintFont()
      {
         PrintJob pj = getToolkit().getPrintJob(null, "Printer", null);
         if (pj != null)
         {
            for (int i=1; i<=3; i++)
            {
               Graphics pg = pj.getGraphics();
               if (pg != null)
               {
                  pg.setFont(new Font("TimesRoman", Font.PLAIN, 16));
                  pg.setColor(Color.black);
                  pg.drawRect(100, 100, 100, 100);
                  pg.drawString("Page " + i, 600, 900);
                  pg.drawString("TimesRoman", 500, 900);
               }
               System.out.println("Dispose");
               pg.dispose();
            }
            pj.end();
            System.out.println("End");
         }
       }
       public static void main(String args[])
      {
          UIFrame f = new PrintFont();
         System.exit(0);
      }
   }

A workaround for this problem is to select a different attribute (font/color) and do a drawString of an empty string, then select back in the desired attribute.

A workaround for the translation accumulation issue is to get your current translation and set the translation to the inverted values:

   try {
      com.ms.awt.GraphicsX gx = (com.ms.awt.GraphicsX) printGraphics;
      Point pt = gx.getTranslation();
      gx.translate(-pt.x, -pt.y);
   } catch (Exception e) {
 }


Additional query words: print font
Keywords : JVM
Technology : kbInetDev internet
Version : WINDOWS:1.1,2.0,2.01
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.