如何以类似矩阵的结构显示条形码? [英] How to display barcodes in a matrix-like structure?
问题描述
如何显示不同的条形码 PDF页面中的多个列使用 itext 库生成 java ?我必须在同一个PDF页面中以三列显示12个条形码,每个条形码包含4个条形码(换句话说,它是一个4乘3的矩阵)。
How can I display different barcodes in multiple columns in a PDF page using itext library to generate pdfs in java? I have to display 12 barcodes in the same PDF page in three columns, each one contains 4 barcodes (in other words it is a 4 by 3 matrix).
推荐答案
我已经制作了一个条形码示例,它可以满足您的需求。请参阅生成的pdf: barcodes_table.pdf
I've made a Barcodes example that does exactly what you need. See the resulting pdf: barcodes_table.pdf
没什么难的。您只需创建一个包含4列的表,然后添加12个单元格:
There's nothing difficult about it. You just create a table with 4 column and you add 12 cell:
PdfPTable table = new PdfPTable(4);
table.setWidthPercentage(100);
for (int i = 0; i < 12; i++) {
table.addCell(createBarcode(writer, String.format("%08d", i)));
}
createBarcode()
方法创建具有条形码的细胞:
The createBarcode()
method creates a cell with a barcode:
public static PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException {
BarcodeEAN barcode = new BarcodeEAN();
barcode.setCodeType(Barcode.EAN8);
barcode.setCode(code);
PdfPCell cell = new PdfPCell(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true);
cell.setPadding(10);
return cell;
}
这篇关于如何以类似矩阵的结构显示条形码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!