admin管理员组文章数量:1287086
I design receipt in Jasper report with width 76mm and height according to report(dynamic). I set margin 1.7mm to left and right and 9mm to top and bottom. Also, in receipt printer (XP-80C), I set paper width 80(76)mm paper size. But when I print, it add margin left size a lot, that is why the right size of receipt gets cut and printed on left side as shown in the image.
here is the Java code,
JasperCompileManagerpileReportToFile("KLMSale.jrxml", "KLMSale.jasper");
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("KLMSale.jasper");
Map<String, Object> parameters = new HashMap<>();
parameters.put("saleId", Integer.parseInt(jTextField1.getText()));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
// Print settings for 76mm paper
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 76, 350, MediaPrintableArea.MM)); // 76mm width
printRequestAttributeSet.add(new Copies(1));
// Export and Print
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, receiptPrinter);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.exportReport();
Image of receipt after print:
How can I correct the left margin?
I design receipt in Jasper report with width 76mm and height according to report(dynamic). I set margin 1.7mm to left and right and 9mm to top and bottom. Also, in receipt printer (XP-80C), I set paper width 80(76)mm paper size. But when I print, it add margin left size a lot, that is why the right size of receipt gets cut and printed on left side as shown in the image.
here is the Java code,
JasperCompileManagerpileReportToFile("KLMSale.jrxml", "KLMSale.jasper");
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("KLMSale.jasper");
Map<String, Object> parameters = new HashMap<>();
parameters.put("saleId", Integer.parseInt(jTextField1.getText()));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
// Print settings for 76mm paper
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 76, 350, MediaPrintableArea.MM)); // 76mm width
printRequestAttributeSet.add(new Copies(1));
// Export and Print
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, receiptPrinter);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.exportReport();
Image of receipt after print:
How can I correct the left margin?
Share Improve this question edited Feb 25 at 7:24 Vishakha Pol asked Feb 25 at 7:02 Vishakha PolVishakha Pol 801 silver badge8 bronze badges1 Answer
Reset to default 0Try below method please:
Add the custom page size:
MediaSize mediaSize = new MediaSize(76, 350, MediaSize.MM);
MediaSizeName mediaSizeName = MediaSize.findMedia(76, 350, MediaSize.MM);
printRequestAttributeSet.add(mediaSizeName);
Then, Disable any printer margins
printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 76, 350, MediaPrintableArea.MM))
Set display dialog to false to prevent margin overrides before exporting
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
In your JRXML, set the margin to 0:
<jasperReport
pageWidth="215"
pageHeight="842"
columnWidth="215"
leftMargin="0"
rightMargin="0"
topMargin="0"
bottomMargin="0">
本文标签: javaJasper report printing on receipt printerStack Overflow
版权声明:本文标题:java - Jasper report printing on receipt printer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741223811a2361479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论