gpt4 book ai didi

java - 如何打印报告

转载 作者:行者123 更新时间:2023-12-01 08:14:55 24 4
gpt4 key购买 nike

我想打印一份 JR 报告。

我正在尝试这段代码

JasperPrint jp = new JasperFillManager().fillReport("billReport", billId, 
"jdbc:mysql://localhost/kpc_hospital");
JasperPrintManager.printReport(jp, true)

但是这段代码不起作用。

最佳答案

您可以使用不同的方法直接打印 Jasper 报告,而不是显示打印对话框。

最简单的方法是:

    Connection con;
String url="jdbc:mysql://localhost/mydb";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=(Connection) DriverManager.getConnection(url,"root","");
JasperReport jasperReport = JasperCompileManager.compileReport(fileName);
JasperPrint print = JasperFillManager.fillReport(jasperReport, parameter, con);
print.setPageHeight(100);
print.setPageWidth(80);
print.setOrientation(jasperReport.getOrientationValue().LANDSCAPE);
JasperPrintManager.printReport(print,false);

您还可以使用这个:

    PrinterJob job = PrinterJob.getPrinterJob();
int selectedService = 0;
selectedService = 0;
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(OrientationRequested.PORTRAIT);
printRequestAttributeSet.add(MediaSizeName.ISO_A0);
MediaSizeName mediaSizeName = MediaSize.findMedia(64,25,MediaPrintableArea.MM);
printRequestAttributeSet.add(mediaSizeName);
printRequestAttributeSet.add(new Copies(1));
JRPrintServiceExporter exporter;
exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasper_print);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();
job.print(printRequestAttributeSet);

关于java - 如何打印报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14285678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com