文本下的Itext条形码

时间:2015-02-20 10:54:09

标签: java itext

当我使用code128.createImageWithBarcode()创建图像时,条形码下的文字会出现在文档中,但当我尝试使用createAwtImage创建并稍后将其保存到光盘时,条形码下的文字会消失。关于如何处理它的任何想法?

Barcode128 code128 = new Barcode128();
code128.setCode(code.trim());
code128.setCodeType(Barcode128.CODE128);
Image code128Image = code128.createImageWithBarcode(cb, null, null);
java.awt.Image imgShipBarCode =  code128.createAwtImage(Color.white, Color.black);
int w = imgShipBarCode.getWidth(null);
int h = imgShipBarCode.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB;  // other options
BufferedImage dest = new BufferedImage(w, h, type);
Graphics2D g2 = dest.createGraphics();
g2.drawImage(imgShipBarCode, 0, 0, null);
g2.dispose();
File outputfile = new File("c:\\image.jpg");
ImageIO.write(dest, "jpg", outputfile);     
code128Image.setAbsolutePosition(10,700);
code128Image.scalePercent(125);
doc.add(code128Image);

由于

1 个答案:

答案 0 :(得分:0)

将字体设置为空

  

code128.Font = null;