• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

java.awt.print.Book -> wrong pages

Hi.

I am using the java.awt.print.Book to print out a quite complex document. Generating the book-object works fine, the preview which is displayed to the user before showing the PrintDialog does show the desired document.

The problem is when the user confirms the PrintDialog, always only the first 7 pages out of about 16 are printed. Even if I select "Pages 1 to 1" in the PrintDialog, I get the first 7 pages. I guess the error must be where I set and call the PrintDialog. This code is posted below.

Any hints are greatly appreciated.

     private void printBook(Book book, int selectedPage)
     {
         PrinterJob pj = PrinterJob.getPrinterJob();
         pj.setPageable(book);
         pj.setCopies(1);
         pj.setJobName("MyPrintJob");
         
         int[][] pageRange = {{(selectedPage==0)?1:selectedPage, (selectedPage==0)?book.getNumberOfPages():selectedPage}};        
         
         HashPrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
         attributeSet.add(new PageRanges(pageRange));
         attributeSet.add(OrientationRequested.PORTRAIT);
         
         if (pj.printDialog(attributeSet))
         {
              try
                  {
                    pj.print();
              }
              catch (PrinterException pe)
                  {
                   pe.printStackTrace();
                  }
         }
         
     }
0
AIndy
Asked:
AIndy
1 Solution
 
In-DCommented:
Change your code to the following :


        if (pj.printDialog(attributeSet))
        {
             try
                 {
                   pj.print(attributeSet);
             }
             catch (PrinterException pe)
                 {
                  pe.printStackTrace();
                 }
        }

regards,
In-D
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now