2013-04-18 44 views
0

我嘗試在獨立的Java應用程序中使用燒烤條形碼生成器,並且能夠打印圖像中顯示的具有條形碼編號的條形碼。燒烤條形碼生成器不會顯示帶有Web應用程序的條形碼號碼

enter image description here

但是,當我從彈簧web應用程序執行相同的方法,將所生成的條形碼不顯示條形碼數如下面的圖像。我正在使用相同的文件路徑來保存圖像並對目錄具有完整的rw權限。你對此有什麼線索,由於

enter image description here

我使用下面的代碼片段

barcode = BarcodeFactory.createCode128A(barcode_Id); 
File f = new File("/opt/rd/barcode/"+barcode_Id+".png"); 
BarcodeImageHandler.savePNG(barcode, f); 
+0

我目前遇到同樣的問題。你有沒有遇到過一個解決方案? –

回答

0

我在Grails的設置我的條形碼字體和覆蓋calculateSize修復了這個問題()方法在條碼

private Dimension calculateSize(){ 
    Dimension d = new Dimension(); 
    if(EnvironmentFactory.getEnvironment() instanceof HeadlessEnvironment) 
    try 
    { 

     if(font == null) 
     { 
      d = draw(new SizingOutput(font, getForeground(), getBackground()), 0, 0, barWidth, barHeight); 
     } else 
     { 
      java.awt.FontMetrics fontMetrics = getFontMetrics(font); 
      d = draw(new SizingOutput(font, fontMetrics, getForeground(), getBackground()), 0, 0, barWidth, barHeight); 
     } 
    } 
    catch(OutputException e) 
    { 
     e.printStackTrace(); 
    } 
    else 
    try 
    { 
     java.awt.FontMetrics fontMetrics = null; 
     if(font != null) 
     fontMetrics = getFontMetrics(font); 
     d = draw(new SizingOutput(font, fontMetrics, getForeground(), getBackground()), 0, 0, barWidth, barHeight); 
    } 
    catch(OutputException e) { } 
    return d; 
} 

sourceforge中的This thread可以在這個問題上找到更多的信息。