Adding more text to a cell in table in itext

后端 未结 1 943
独厮守ぢ
独厮守ぢ 2020-12-21 14:05

I am trying to add some text with a bar code in a table cell using itext as per the following code but it does not show in the pdf file. i tried adding chunks and paragraph.

相关标签:
1条回答
  • 2020-12-21 14:33

    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);
    
    0 讨论(0)
提交回复
热议问题