我有以下代码用于将发票打印到zt410-300dpi打印机:
private static void jasperPrint56(JasperPrint jasperPrint, String printerName) throws JRException, IOException {
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(new PrinterName(printerName, null));
PrintService[] printService = PrintServiceLookup.lookupPrintServices(null, printServiceAttributeSet);
int selectedService = 0;
try {
job.setPrintService(printService[selectedService]);
} catch (Exception e) {
System.out.println(e);
}
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
configuration.setPrintService(job.getPrintService());
configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
configuration.setDisplayPageDialog(false);
configuration.setDisplayPrintDialog(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
}
这不会打印完整的报告,只打印约30%的报告。 在jrxml文件中,我已经定义了页面宽度和高度,如下所示:
页宽=" 288" pageHeight =" 432"
转换为72 dpi的碧玉后,其中4英寸x 6英寸
在打印机属性中,我也将页面大小设置为4x6。