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

Printing in Java 1.2 does not work (55584 again, more info) for large images

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.0, 1.2.1, 1.2.2
    • client-libs
    • 2d
    • generic, x86
    • generic, windows_95, windows_98, windows_nt

    Description

      : printing java.awt.Rectangle[x=72,y=290,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=302,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=313,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=325,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=336,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=348,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=360,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=371,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=383,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=394,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=406,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=417,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=429,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=440,width=468,height=13]
      3: printing java.awt.Rectangle[x=72,y=72,width=468,height=648]
      */

      results of java -fullversion:
      java full version "JDK-1.2-V"

      system information:
      i am using Windows 95, version 4.00.950 C with IE 4.0 4.72.3110.8
      Pentium II, 266MHZ, 128M RAM. i am printing PostScript to an Apple LaserWriter
      over our internal network. i also printed to a file and viewed the file with
      GhostScript/GSView (same results). spool data format is RAW.
      (Review ID: 55587)
      ======================================================================

      /*
       This cut down version is easier to follow
      */

      import java.awt.*;
      import java.awt.print.*;
      import java.awt.image.*;

      public class TallImagePrinter extends Component implements Printable {

         Image img;

         public static void main(String args[]) {
            TallImagePrinter ip = new TallImagePrinter();
         }

         public TallImagePrinter () {

            img = Toolkit.getDefaultToolkit().getImage("BigImage.jpg");
            MediaTracker mt = new MediaTracker(this);
            mt.addImage(img, 0);
            try {
                mt.waitForAll();
            } catch (Exception e) {};
            PrinterJob printerJob = PrinterJob.getPrinterJob();
            printerJob.setPrintable(this);
         
            if (printerJob.printDialog()) {
                try {
                    printerJob.print();
                    System.err.println("finished printing!");
                } catch (PrinterException ex) {
                }
            }
            System.exit(0);
         }
         
         public int print(Graphics g, PageFormat pf, int pi)
                                     throws PrinterException {

            Graphics2D g2 = (Graphics2D) g;
            System.out.println(pi+": printing "+g2.getClipRect());
            // next line assumes page's imageable area is of equal height
            double transY = pf.getImageableHeight() * pi;
            if (transY >= img.getHeight(null)) {
               return Printable.NO_SUCH_PAGE;
            }
            g2.translate(pf.getImageableX(), pf.getImageableY());
            
            g2.drawImage(img, 0, (int)-transY, null);
            return Printable.PAGE_EXISTS;
         }
      }
      Name: vi73552 Date: 04/26/99

      (i already filed this, internal review ID = 55584). this is the same
      but has more info on my system:

      steps:
      compile and run class below (put a large image called BigImage.gif into
      the classpath).
      expected behavior:
      print image over more than one page
      actual behavior:
      only parts of the image print.

      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import javax.swing.*;


      import java.awt.print.PrinterJob;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PageFormat;

      import java.awt.image.*;
      import java.net.URL;

      /**
      * Simple application to print one particular image called BigImage.jpg. Displays the
      * image, just to make sure the image is actually there and intact.
      * expected behavior:
      * print the image over three pages
      * actual bahavior:
      * only the bottom part of the image prints on page 1 and 2. in addition, it seems to
      * be the wrong part of the image.
      * page 3 prints fine for the most part.
      * i tried different images (gifs, jpegs). all showed the same behavior. the last page (the
      * one where only a small part of the image is drawn is the only one that prints fine (if
      * one does not change the page margins).
      * other things i noted:
      * 1) images significantly smaller than the page seem to print fine, except when the
      * margins are changed in the page dialog. if the margins are changed to minimum,
      * only parts of the image are painted.
      * 2) the painted parts are:
      * sometimes the top (not repro-able when)
      * always part of the bottom
      * never the part in the middle
      * 3) i experimented with drawing rects on top of the image.
      * this results in the rects drawing where the image draws, too.
      * where the image is missing, the rects are missing as well. drawing
      * rects without an image is fine.
      * 4) on the pages where only the bottom part prints, the rect at the bottom does
      * not print. that leads me to the conclusion that the wrong part of the graphics
      * is being drawn there.
      */

      public class ImagePrinter implements Printable {

      Image _printBuffer;

      public static void main(String args[]) {
      ImagePrinter ip = new ImagePrinter();
      // set up frames and display image
      ip.initFrames();
      // print image
      ip.printImage();
      }

      /**
      * show a JFrame with the image and print it
      */
      public void initFrames() {

      // ----------------------------------------------------------
      // setup code
      // ----------------------------------------------------------
      // create the desktop frame
      JFrame desktopFrame = new JFrame();
      desktopFrame.setSize(300, 300);
      // create the desktop pane
      JDesktopPane desktop = new JDesktopPane();
      desktop.setDesktopManager(new DefaultDesktopManager());
      desktop.setDoubleBuffered(false);

      // and show everything to the user
      desktopFrame.getContentPane().add(desktop);
      desktopFrame.show();

      desktopFrame.addWindowListener(
      new WindowAdapter() {
      public void windowClosing (WindowEvent e) {
      System.exit(0);
      }
      });

      // note: the following image must be in the classpath
      URL url = getClass().getResource("BigImage.gif");
      if (url != null)
      // get the image to print
      _printBuffer = desktopFrame.getToolkit().createImage(url);
      else {
      System.out.println("could not find image");
      System.exit(-1);
      }

      // ----------------------------------------------------------
      // the following code displays the image. it is not neccessary
      // for the bug. just to make sure that nothing is wrong with
      // the image.
      // ----------------------------------------------------------
      // create a really simple component that just draws the image
      JComponent comp = new JComponent() {
      public void paint(Graphics g) {
      g.drawImage(_printBuffer, 0, 0, null);
      }
      };

      // create an internal frame that shows the component
      JInternalFrame frame = new JInternalFrame("print preview");
      comp.setBounds(0, 0, 300, 300);
      comp.setPreferredSize(new Dimension(300, 300));
      frame.setBounds(0, 0, 300, 300);
      frame.setPreferredSize(new Dimension(300, 300));
      frame.setResizable(true);
      frame.getContentPane().add(comp);
      desktop.add(frame);
      frame.pack();
      frame.show();
      }

      // ----------------------------------------------------------
      // printing code (this is the important part). also see the
      // print(...) method below.
      // ----------------------------------------------------------
      /**
      * prints the _printBuffer. brings up page format and print dialogs.
      */
      public void printImage() {

      // get printer job
      PrinterJob printerJob = PrinterJob.getPrinterJob();

      // Ask user for page format (e.g., portrait/landscape)
             PageFormat pf = printerJob.pageDialog(printerJob.defaultPage());

      // set this as the printable
      printerJob.setPrintable(this, pf);

      // show print dialog and print
      if (printerJob.printDialog()) {
      try {
      printerJob.print();
      System.out.println("finished printing!");
      } catch (Exception ex) {
      ex.printStackTrace();
      }
      }
      }

      // ----------------------------------------------------------
      // Printable interface method.
      // ----------------------------------------------------------
      /**
      * Printable interface method implementation.
      * this prints the _printBuffer over several pages.
      */
      public int print(Graphics g, PageFormat pf, int pi)
                                   throws PrinterException {

      Graphics2D g2 = (Graphics2D) g;
      // debug
      System.out.println(pi+": printing "+g2.getClipRect());
      // adjust for page number
      double transY = pf.getImageableHeight() * pi;
      if (transY >= _printBuffer.getHeight(null)) {
      return Printable.NO_SUCH_PAGE;
      }
      // set origin to printable origin
      g2.translate(pf.getImageableX(), pf.getImageableY());

      // draw the appropriate part of the image
      g2.drawImage(_printBuffer, 0, (int)-transY, null);

      // experiment: draw rects on top of image
      g2.setColor(Color.black);
      g2.drawRect(0, 0, 5, 5000); // a rect on the left
      g2.drawRect(0, 0, 5000, 5); // a rect on the top
      g2.drawRect(0, (int)pf.getImageableHeight()-6, 5000, (int)pf.getImageableHeight()-1); // a rect on the bottom
      g2.drawRect((int)pf.getImageableWidth()-6, 0, (int)pf.getImageableWidth()-1, 5000); // a rect on the right

      return Printable.PAGE_EXISTS;
      }
      }
      /*
      note: print generates the following output for an image that goes over 3 pages:

      0: printing java.awt.Rectangle[x=72,y=72,width=468,height=648]
      0: printing java.awt.Rectangle[x=72,y=72,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=83,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=95,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=106,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=118,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=129,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=141,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=152,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=164,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=175,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=187,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=198,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=210,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=221,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=233,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=244,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=256,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=267,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=279,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=290,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=302,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=313,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=325,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=336,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=348,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=360,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=371,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=383,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=394,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=406,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=417,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=429,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=440,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=452,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=463,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=475,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=486,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=498,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=509,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=521,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=532,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=544,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=555,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=567,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=578,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=590,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=601,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=613,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=624,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=636,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=648,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=659,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=671,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=682,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=694,width=468,height=12]
      0: printing java.awt.Rectangle[x=72,y=705,width=468,height=13]
      0: printing java.awt.Rectangle[x=72,y=717,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=72,width=468,height=648]
      1: printing java.awt.Rectangle[x=72,y=72,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=83,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=95,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=106,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=118,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=129,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=141,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=152,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=164,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=175,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=187,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=198,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=210,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=221,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=233,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=244,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=256,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=267,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=279,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=290,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=302,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=313,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=325,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=336,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=348,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=360,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=371,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=383,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=394,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=406,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=417,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=429,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=440,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=452,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=463,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=475,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=486,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=498,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=509,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=521,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=532,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=544,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=555,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=567,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=578,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=590,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=601,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=613,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=624,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=636,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=648,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=659,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=671,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=682,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=694,width=468,height=12]
      1: printing java.awt.Rectangle[x=72,y=705,width=468,height=13]
      1: printing java.awt.Rectangle[x=72,y=717,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=72,width=468,height=648]
      2: printing java.awt.Rectangle[x=72,y=72,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=83,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=95,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=106,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=118,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=129,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=141,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=152,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=164,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=175,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=187,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=198,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=210,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=221,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=233,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=244,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=256,width=468,height=12]
      2: printing java.awt.Rectangle[x=72,y=267,width=468,height=13]
      2: printing java.awt.Rectangle[x=72,y=279,width=468,height=12]
      2

      Attachments

        Issue Links

          Activity

            People

              prr Philip Race
              vasya Vassili Igouchkine (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: