Unwanted margins on custom paper size Jasper Reports print jobs

15
I searched over and over again on the internet, but couldn't find nothing to help me.
 
We're having some problems with custom page size reports. It seems that the printing routine is always
adding a default margin to the print job, but in the JRXML we have defined a zero margin for the report.
This problem affects specially reports printed on label printers, as the report is suppose to be at the exact size
of the label, it actually, because of the inappropriate margin, leaves some labels unprinted before actually printing the
report or printing on report divided in two label.
Just for clarification, we use the class  to send the job to the printer. And generating the report in IReport, in preview, the
report is shown correctly, but the problem persists on print.
I'm sending together the report's JRXML for yours consideration
 
Thanks in advance for any help.
Attachments: 
alan_s_carneiro's picture
Joined: Aug 22 2012 - 7:22am
Last seen: 1 year 7 months ago

Had the same issue. It looks like imageable are of thermal printer paper is not the same as paper size.

This worked for me:

// default jasper context
JasperReportsContext CTX = DefaultJasperReportsContext.getInstance();
 
JasperPrint jp = ... // your filled jasper print object
PrintService ps = ... // your printer
 
 
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(ps);
PageFormat fmt = job.getPageFormat(null);
Paper p = fmt.getPaper();
// set imageable area the size of whole printer paper
p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
fmt.setPaper(p);
 
switch (jp.getOrientationValue()) {
    case LANDSCAPE:
        fmt.setOrientation(PageFormat.LANDSCAPE);
        break;
    case PORTRAIT:
        fmt.setOrientation(PageFormat.PORTRAIT);
        break;
}
job.setPrintable(new JRPrinterAWT(CTX, jp), fmt);
job.print();

beldy - 10 months 2 weeks ago

0 Answers:

No answers yet
Feedback
randomness