简体   繁体   中英

jasper report printing

I have created a Jasper report with size 64X24 MM Size. I have also written a code for printing a jasper report. But when I run this code, jasper report cannot print in proper format.

And when I can taking a print using JasperReportViewer's Print menu then it will print in proprly. But I dont want to use JasperReportViewer. I have to jasper report directly set to printer.

My Code is:

   JasperReport jasper_rep = JasperCompileManager.compileReport("c:\\report1.jrxml");
   JasperPrint jasper_print = JasperFillManager.fillReport(jasper_rep, parametersMap, con);
   JasperViewer.viewReport(jasper_print);
   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);

But it does not give a print in proper format.

Try removing

MediaSizeName mediaSizeName = MediaSize.findMedia(64,25,MediaPrintableArea.MM); printRequestAttributeSet.add(mediaSizeName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM