【问题标题】:Itext barcode under text文本下的 Itext 条码
【发布时间】:2015-02-20 10:54:08
【问题描述】:

当我使用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);

谢谢

【问题讨论】:

  • createAwtImage 只是返回图像,这是设计使然。如果您想要文本或其他任何内容,则必须使用 awt 资源编写它。

标签: java itext


【解决方案1】:

将字体设置为空

code128.Font = null;

【讨论】:

  • 虽然这个答案可能会解决问题,但它的质量确实很低,应该解释一下如何以及为什么将字体设置为null 可以解决问题。 - From Review
  • @Paulo Soares 评论下这个问题是对的,createAwtImage 只是返回图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
  • 2017-01-17
  • 2019-01-24
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
相关资源
最近更新 更多