?
Solved

java.awt.print.Book -> wrong pages

Posted on 2003-04-01
1
Medium Priority
?
316 Views
Last Modified: 2012-08-13
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
Comment
Question by:AIndy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
In-D earned 300 total points
ID: 8244726
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question