I'm printing a Jasper report to a Zebra label printer. The label has a QR code and a number. If I export the report to a PDF file and print it, it prints fine, but if I print it directly from the Java app, the numbers aren't shown. Upon further testing, if I print it directly but if I show the printing dialog and if I erase the margins, then it prints properly as well. I noticed that the dialog adds very significant margins to the report: right (mm): 191,21 and bottom (mm) 229,66.
The report itself doesn't have any margins, and indeed it prints as expected as a pdf file:
leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"
But it seems like they get added when printing with JRPrintServiceExporter with the following code:
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, rpt);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, true); // won't work if false
exporter.exportReport();
How do I remove margins programatically so that I can bypass the printing dialog?