您可能对 文本 模式与 复合 模式感到困惑。
使用
PdfPCell(Image)构造函数时,可以在 文本
模式下创建一个单元格。随后,对的任何后续调用
addElement(Element)都会将单元格切换到 复合
模式,从而删除先前在构造函数中输入的所有内容。
您必须以这种方式更改代码:
PdfPCell cell = new PdfPCell();Barpre128 barpre = new Barpre128();barpre.setCode(pre);Image barpreImage = barpre.createImageWithBarpre(writer.getDirectContent(), baseColor.BLACK, baseColor.GRAY);cell.addElement(barpreImage);Paragraph paragraph = new Paragraph("Hello World"); cell.addElement(paragraph);


