2016-04-11 5 views
-2

zu schreiben Ich habe jasper Bericht verwenden, um einen Bericht in Java zu erstellen, und die meiste Zeit habe ich versucht, den Druckername mit Code einzurichten, aber ich konnte das nicht tun. Bitte helfen Sie mir, wie Druckernamen zu geben, ohne die Verwendung von Druckmanager druckenWissen, um den Druckernamen in Java

try { 
     String comname = ""; 
     comname = "Stars Bombay Sweet (Pvt) Ltd."; 

     JRTableModelDataSource dts = new JRTableModelDataSource(jTable1.getModel()); 
     String path = "D:\\Aster Soft\\Stars Reports\\posh_print\\report1.jrxml"; 
     Map<String, Object> params = new HashMap<String, Object>(); 

     params.put("name", comname); 

     params.put("para1", InvNo.getText()); 
     params.put("para2", dat); 
     params.put("para3", Customer.getText()); 
     params.put("credit", jComboBox1.getSelectedItem()); 

     params.put("Qty", GrossQty.getText()); 
     params.put("TotAmont", TotalAmount.getText()); 
     params.put("Discount", Discount.getText()); 
     params.put("GrossAmont", DisAmount.getText()); 

     JasperReport report = JasperCompileManager.compileReport(path); 
     JasperPrint print = JasperFillManager.fillReport(report, params, dts); 
     JasperViewer.viewReport(print, false); 
     JasperPrintManager.printReport(print, true); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

Antwort

0
 JasperPrint print = JasperFillManager.fillReport(this.class.getResource("/classpath/yourReport.jasper").getPath(), 
      new HashMap(), new yourReportDataSource()); 
     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 &lt; 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]); 

ich unter Blog Link denken helfen Ihnen

http://blog.marcnuri.com/choosing-a-printer-programmatically-in-jasper-reports/

Verwandte Themen