Unwanted margins on custom paper size Jasper Reports print jobs

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email community@tibco.com with questions or issues requiring TIBCO review or response.

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.
alan_s_carneiro's picture
Joined: Aug 22 2012 - 7:22am
Last seen: 4 years 10 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();
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());
switch (jp.getOrientationValue()) {
    case LANDSCAPE:
    case PORTRAIT:
job.setPrintable(new JRPrinterAWT(CTX, jp), fmt);

beldy - 4 years 3 weeks ago

0 Answers:

No answers yet