java如何将表添加到文本区_java – 在itext中向表中的单元格添加更多文本

我正在尝试使用itext按照以下代码在表格单元格中添加一些带条形码的文本,但它不会显示在pdf文件中.我尝试添加块和段.任何有关这方面的帮助将不胜感激.

Barcode128 barcode = new Barcode128();

//barcode.setCodeType(Barcode.EAN8);

barcode.setCode(code);

PdfPCell cell = new PdfPCell(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true);

Paragraph paragraph = new Paragraph("Hello World");

cell.addElement(paragraph);

cell.setPadding(10);

解决方法:

您可能会对文本与复合模式感到困惑.

使用PdfPCell(Image)构造函数时,可以在文本模式下创建单元格.随后对addElement(Element)的任何调用都会将单元格切换为复合模式,删除先前在构造函数中输入的所有内容.

您必须以这种方式更改代码:

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);

标签:java,itext,barcode

来源: https://codeday.me/bug/20191002/1843970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值