[#5227] - PageFormat is't applied in JRView print dialog.

Category:
Bug report
Priority:
Normal
Status:
New
Project: Severity:
Critical
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:

jasperreports.4.0.2
sun java jdk 1.6.0_24
OS - linux.

I am using JRView. Page format is set in jrxml file. But If user tries to print something he must set all parameters( like media, margins, orientation) again. I have written some code to fix that for myself , it's a copypaste from net.sf.jasperreports.engine.print.JRPrinterAWT and sun.print.RasterPrinterJob classes.

Trouble is here (JRPrinterAWT.java):

Book book = new Book();
book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
printJob.setPageable(book);
try
{
if (withPrintDialog)
{
if (printJob.printDialog())
{
printJob.print();
}
else
{
isOK = false;
}
}
else
{
printJob.print();
}
}
catch (Exception ex)
{
throw new JRException("Error printing report.", ex);
}

i do not know why, but PageFormat isn't applied here . User must himself set all parameters of paper . But if I change code in something like this:

PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
attributeSet.add( OrientationRequested.LANDSCAPE );
attributeSet.add( MediaSizeName.ISO_A4 );

Book book = new Book();
book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
printJob.setPageable(book);
try
{
if (withPrintDialog)
{
if (printJob.printDialog(attributeSet))
{
printJob.print(attributeSet);
}
else
{
isOK = false;
}
}
else
{
printJob.print(attributeSet);
}
}
catch (Exception ex)
{
throw new JRException("Error printing report.", ex);
}

it's working . And also where are some troubles while detecting
MediaSizeName by paper width/height. I found code for this in sun.print.RasterPrinterJob source . I don't y think that my solution is good.

this bug was detected in older versions of jasperreports too.

Thank you for attention, sorry for my english.

winterfill's picture
Joined: May 13 2011 - 5:16am
Last seen: 4 months 3 weeks ago
Feedback
randomness