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

Printable.print(...) called 100s of times leading to HUGE print jobs

XMLWordPrintable

    • 2d
    • x86
    • windows_95, windows_nt



      Name: vi73552 Date: 04/14/99


      Here is a modified copy of SimplePrint from the Java2D API Guide.
      As also said in comments, uncommenting chunk 1 causes it to (mostly)
      work (except for a seperate and VERY annoying bug that I hope you fix SOON)
      If you uncomment chunk 2 however, print() get called on the order of 50
      times per page. This cause the simple 5 page job to take 10 minutes to spool
      and then never actually print.

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

      public class SimplePrint implements Printable
      {
          private static Font fnt = new Font("Helvetica",Font.PLAIN,24);

          public static void main(String[] args)
      {
      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintable(new SimplePrint());
      if (job.printDialog())
      {
      try { job.print(); }
      catch (Exception e) { e.printStackTrace(); }
      }
      System.exit(0);
      }

          public int print(Graphics g, PageFormat pf, int pageIndex)
      throws PrinterException
      {
      System.out.println("DEBUG: print called for page " + pageIndex);

      if (pageIndex >= 5) return Printable.NO_SUCH_PAGE;
      g.setFont(fnt);
      g.setColor(Color.black);

      Rectangle r = g.getClipBounds();
      if (r == null)
      throw new PrinterException("Graphics has no clipBounds!");

      ///////// CHUNK 1 ///////////
      // causes only the first page to print see bug 4201748
      // print() is called twice per page
      // g.drawString("Page " + (pageIndex+1), 100, 100);

      //////// CHUNK 2 ///////////
      // caused print(...) to be called almost 40 times for each page.
      // results in HUGE print jobs that take WAY too long.
      // also seen in bug #4186108 and comments
      // When it does finally spool, it does not print anything.

      BufferedImage im = ((Graphics2D)g).getDeviceConfiguration().
      createCompatibleImage(r.width,r.height);
       
      Graphics2D ig = im.createGraphics();
      ig.setFont(fnt);
      ig.setColor(Color.black);
      ig.drawString("Page " + (pageIndex+1), 100, 100);
      ig.dispose();

      g.drawImage(im, r.x, r.y, null);

      return Printable.PAGE_EXISTS;
      }
      }


      I am using JDK1.2.1 (Classic VM build 1.2.1-A native threads) on
      Win95 4.00.950B with an HP DeskJet 560C printer.
      (Review ID: 56589)
      ======================================================================

            mpeircesunw Michael Peirce (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: