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

PrinterJob carries over some values between calls to print.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.4.2
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
      2d
    • Understanding:
      Fix Understood
    • CPU:
      sparc
    • OS:
      solaris_9

      Description

      Although neither explicitly supported or prohibited, some programs do follow
      a pattern of
      PrinterJob pj = PrinterJob.getPrinterJob();
      pj.setPageable(..)
      pj.print(..)
      pj.setPageable(..)
      pj.print(..)

      It appears that on the second call to print() some "state" calculated
      for the first call is assumed to apply to the second call too.
      But this happens only in even narrower and more questionable use cases
      than that above - eg mixing print() and print(AttributeSet) calls.
      For example a program below creates 2 books. It prints the first with
      a pagerange of 1,1 but the 2nd with no page range, but that of the
      first carries over so it also only prints 1 page.
      The main culprit is that the no-args print() uses an internal
      attribute set which is presumed to carry over information not supplied
      by the client directly but created during a call to no-args printDialog()
      The attribute set passed in a by the app should not be remembered
      across calls.

      import java.awt.*;
      import java.awt.print.*;
      import javax.print.*;
      import javax.print.attribute.*;
      import javax.print.attribute.standard.*;

      public class pageranges implements Printable {

          public static void main(String args[]) {
      PrinterJob pjob = PrinterJob.getPrinterJob();
      PageFormat pf = pjob.defaultPage();
      Book book = new Book();

      book.append(new pageranges(), pf);
      book.append(new pageranges(), pf);
      pjob.setPageable(book);
              PrintRequestAttributeSet aset =
                  new HashPrintRequestAttributeSet();
              aset.add(new PageRanges(1,1));
              PrintService service = pjob.getPrintService();
              AttributeSet unsupportedSet =
                service.getUnsupportedAttributes(
                   DocFlavor.SERVICE_FORMATTED.PAGEABLE, aset);
              if (unsupportedSet != null) {
                System.out.println("job unsupported - exiting");
                System.exit(0);
              }
      try {
                 
      pjob.print(aset);
      } catch (PrinterException e) {
      throw new RuntimeException(e.getMessage());
      }

      Book book2 = new Book();
      book2.append(new prbook(), pf);
      book2.append(new pageranges(), pf);
      pjob.setPageable(book2);

      try {
      pjob.print();
      } catch (PrinterException e) {
      throw new RuntimeException(e.getMessage());
      }
              System.exit(0);
          }

          public int print(Graphics g, PageFormat pf, int pageIndex) {
              System.out.println("print " + pageIndex);
      g.drawString("hello", 100, 100);
      return PAGE_EXISTS;
          }
      }

        Attachments

          Activity

            People

            Assignee:
            psadhukhan Prasanta Sadhukhan
            Reporter:
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: