gpt4 book ai didi

java - 如何以编程方式打印 Jasper 报告

转载 作者:搜寻专家 更新时间:2023-11-01 02:49:55 28 4
gpt4 key购买 nike

我必须编写代码来生成包含图像的 Jasper 报告。我想将碧 Jade 报告发送给打印机。我尝试了一个代码:

    String Report = "C:\\Template\\"+file_name+".jrxml";//my Jasper report file
JasperPrint print = JasperFillManager.fillReport(Report,null,con);
PrinterJob job = PrinterJob.getPrinterJob();
/* Create an array of PrintServices */
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
int selectedService = 0;
/* Scan found services to see if anyone suits our needs *
for(int i = 0; i < services.length;i++)
{
if(services[i].getName().toUpperCase().contains("Your printer's name"))
{
/*If the service is named as what we are querying we select it */
selectedService = i;
}
}
job.setPrintService(services[selectedService]);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
MediaSizeName mediaSizeName = MediaSize.findMedia(4,4,MediaPrintableArea.INCH);
printRequestAttributeSet.add(mediaSizeName);
printRequestAttributeSet.add(new Copies(1));
JRPrintServiceExporter exporter;
exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
/* We set the selected service and pass it as a paramenter */
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
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();

但它给我的错误是:

   net.sf.jasperreports.engine.JRException: Error loading object from file : C:\Template\Alcon_Ele_Temp1.jrxml

最佳答案

您必须加载 jasper print no jasper xml。有一个页面也许可以帮助您 http://jasperreports.sourceforge.net/sample.reference/printservice/index.html

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

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