2017-04-02 210 views
0

我創建了一個碧玉報告(發票)文件並通過JButton運行它。當我點擊按鈕時,它會按預期顯示預覽,但是當我點擊Jasper Viewer中的打印按鈕以使用點陣打印機(TVS 240 star)進行打印時,頁面上的字體(硬拷貝)彼此重疊並且大小也發生了變化。Jasper報告字體在點陣打印機打印時重疊

我該如何解決這個問題?

(頁面大小5英寸寬6英寸高度/ Arial字體的Unicode MS,9)

public void bill(){ 
    if(textField_10.getText().equals("")) 
      { 
     JOptionPane.showMessageDialog(null,"Enter Bill no. !","Invoice", getDefaultCloseOperation()); 
     textField_10.grabFocus(); 
    } 
    else{ 
    try{ 
     String para=textField_7.getText(); 
     String para1=textField_8.getText(); 
     String para2=textField_9.getText(); 
     String para3=textField_10.getText(); 
     String sourceName="/DBcon/new.jrxml"; 
     //String sourceName="/DBcon/Invoice.jrxml"; 
     java.io.InputStream in=null; 

    HashMap<String, Object> hm=new HashMap<String,Object>(); 
    hm.put("Retailer_Name",para); //jasper report parameter passing 
    hm.put("Address",para1); 
    hm.put("Contact",para2); 
    hm.put("Billno",para3); 

    in=getClass().getResourceAsStream(sourceName); 
    JasperReport jr=JasperCompileManager.compileReport(in); 
    JasperPrint jp=JasperFillManager.fillReport(jr,hm,con); 
    JasperViewer.viewReport(jp,false); 
    // JasperPrintManager.printReport(jp,true); 
    //JasperExportManager.exportReportToPdfFile(jp, destinationFile); 
    Exporter exp = new JRDocxExporter(); 
    exp.setExporterInput(new SimpleExporterInput(jp)); 
    File exportReportFile = new File("C:\\Users\\Public\\Documents\\invoice.docx"); 
    exp.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFile)); 

    exp.exportReport();   
} 
    catch(Exception e){ 
     e.printStackTrace(); 
     JOptionPane.showMessageDialog(null,"Close previous invoice"); 
    } 
    } 
} 
+0

蹊蹺* JRXML *(報告的模板) –

回答

1

發生在大多數點陣打印機此錯誤,你可以通過打印通過MS Word或PDF報告克服這個讀者。

JasperPrint jpd = JasperFillManager.fillReport(jrd, para, db.mycon()); 
File f = new File("C:\\PrintTemp\\"); //create a folder in c drive 
if (!f.exists()) { 
    f.mkdir(); 
} 
//delete previous files in the folder(this is not necessary) 
for (File file : f.listFiles()) { 
    if (!file.isDirectory()) { 
     file.delete(); 
    } 
} 

File destFile = new File(f + "print.pdf"); 
JasperExportManager.exportReportToPdfFile(jpd, destFile); 
//print the file 
Desktop desktop = Desktop.getDesktop(); 
if (desktop.isSupported(Desktop.Action.PRINT)) { 
    desktop.print(new File(destFile)); 
} 

默認的PDF閱讀器會打開並打印通過默認的打印機打印文件