gpt4 book ai didi

java - 烧烤条形码生成器不使用网络应用程序显示条形码编号

转载 作者:行者123 更新时间:2023-12-01 04:44:20 30 4
gpt4 key购买 nike

我尝试在独立的 Java 应用程序中使用 Barbecue 条形码生成器,并且能够打印带有图像中显示的条形码编号的条形码。

enter image description here

但是当我从 Spring Web 应用程序执行相同的方法时,生成的条形码不会显示条形码编号,如下图所示。我使用相同的文件路径来保存图像并对该目录具有完全的读写权限。您对此有任何线索吗,谢谢

enter image description here

我正在使用下面的代码片段

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

最佳答案

我已经在 Grails 中解决了这个问题,为我的条形码设置字体并覆盖 Barcode 中的 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;
}

This thread sourceforge 可以进一步阐明这个问题。

关于java - 烧烤条形码生成器不使用网络应用程序显示条形码编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16086694/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com