You are probably confused by text vs. composite mode.
When using the PdfPCell(Image)
constructor, you create a cell in text mode. Any subsequent call to addElement(Element)
will then switch the cell to composite mode, removing all content previously entered in the constructor.
You'll have to change your code that way:
PdfPCell cell = new PdfPCell();
Barcode128 barcode = new Barcode128();
barcode.setCode(code);
Image barcodeImage = barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY);
cell.addElement(barcodeImage);
Paragraph paragraph = new Paragraph("Hello World");
cell.addElement(paragraph);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…