AIndy
asked on
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:sele ctedPage, (selectedPage==0)?book.get NumberOfPa ges():sele ctedPage}} ;
HashPrintRequestAttributeS et attributeSet = new HashPrintRequestAttributeS et();
attributeSet.add(new PageRanges(pageRange));
attributeSet.add(Orientati onRequeste d.PORTRAIT );
if (pj.printDialog(attributeS et))
{
try
{
pj.print();
}
catch (PrinterException pe)
{
pe.printStackTrace();
}
}
}
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:sele
HashPrintRequestAttributeS
attributeSet.add(new PageRanges(pageRange));
attributeSet.add(Orientati
if (pj.printDialog(attributeS
{
try
{
pj.print();
}
catch (PrinterException pe)
{
pe.printStackTrace();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.