rodrigo_correa Posted December 9, 2009 Share Posted December 9, 2009 Hi every one.I have a program that generates reports, then I send them to printer (shared printers on network pc's) and finally the report is exported to pdf format and saved. The problem is at printing time, the saved pdf file is always ok, but some times (may be one report in 100) the printed page is incomplete, some fields, lines or even text are not printed. If I process once again the print is ok. This behavior seems to be random.Please help me, any idea????I'm using :jasperreports-3.6.0.jarWindows server 2003the system is runing under tomcat 5.0 Thanks in advanceCode:Main program.........PrintReport printReport = new PrintReport(jp, printerName, copies);printReport.start();byte[] pdfByte = null;try {pdfByte = JasperExportManager.exportReportToPdf(jp);} catch(JRException e) {System.err.println(e.getMessage());}........=====================================================================Print class...public class PrintReport extends Thread{public static final String PRINTER_JOB_NAME_KEY ="org.jfree.report.modules.output.pageable.graphics.print.JobName";private JasperPrint jp;private String printerName;private int copies;public PrintReport(JasperPrint jp, String printerName, int copies){this.jp = jp;this.printerName = printerName;this.copies = copies;}/public void run(){if(jp == null) {System.err.println(" ERROR grave, el reporte es NULO");}PrinterJob job = PrinterJob.getPrinterJob();AttributeSet aset3 = new HashAttributeSet();aset3.add(new PrinterName(printerName, null)); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, aset3);// Si no estuvo la impresora no hacemos nada.if(services.length < 1) {System.err.println(printerName + " Impresora no definida");return;}try {job.setPrintService(services[0]);PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();printRequestAttributeSet.add(new Copies(copies));printRequestAttributeSet.add(new JobName(jp.getName(), null));JRPrintServiceExporter exporter;exporter = new JRPrintServiceExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);/* We set the selected service and pass it as a paramenter */exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[0]);exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[0].getAttributes());exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);exporter.exportReport();System.out.println("Impresion OK");} catch (JRException e) {System.err.println(e);} catch (PrinterException e) {System.err.println(e);}}} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now