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

Printing more than 1 page using PrinterJob.print(): long time, huge files.

    XMLWordPrintable

Details

    • 2d
    • generic, x86
    • generic, windows_95, windows_nt

    Description



      Name: tb29552 Date: 10/30/98


      /*
      When I print more than a page of text, the
      "Progress" column in the print queue box will
      show "0 bytes of 900Kb", 2 pages will be
      "0 bytes of 1.74Mb", 3 pages will be "4.34Mb"
      and so forth. It takes forever just to print
      5 pages of text.

      This does not occur for JDK1.1.6 (using PrintJob).
      Printing 3 pages of text is almost instantaneous.
      Progress column will show "0 bytes of 22.5Kb" for
      3 pages compared with JDK1.2's 4.34MB.

      Sample code:
      ------------
      */

      /* source for Printable implementation */

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

      public class Painter implements Printable {

          Font textFont = new Font("Monospaced", Font.PLAIN, 10);

          public int print(Graphics g, PageFormat pageFormat,
                            int pageIndex)
              throws PrinterException
          {

              g.setColor(Color.black);
              g.setFont(textFont);
              FontMetrics fm = g.getFontMetrics();

              int x = 72;
              int y = 72 + fm.getAscent();

              for (int i = 0; i < 40; i++) {
                  g.drawString("sample line of text", x, y);
                  y += fm.getHeight();
              }
              return Printable.PAGE_EXISTS;
          }
      }
      ---------------------------------------------
      /* source for test stub */

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

      public class test {

          public test () {
              PrinterJob pJ = PrinterJob.getPrinterJob();

              Paper A4_paper = new Paper();
              A4_paper.setSize(595, 845);
              A4_paper.setImageableArea(60, 60, 451, 698);

              PageFormat pF = new PageFormat();
              pF.setOrientation(PageFormat.PORTRAIT);
              pF.setPaper(A4_paper);

              Painter painter = new Painter ();
              Book book = new Book();

              for (int i = 0; i < 5; i++) {
                  book.append(painter, pF);
              }

              pJ.setPageable(book);
              try {
                  pJ.print();
              } catch(PrinterException pE) {
              }
          }

          public static void main(String args[]) {
              test newPrintJob = new test ();
          }
      }
      /*
      Note: Printing was done on HP LaserJet 4V.
      */

      (Review ID: 41670)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mpeircesunw Michael Peirce (Inactive)
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: