iText pdf library
Website search

How to display barcodes in a matrix-like structure?

How can I display different bar codes in multiple columns in a PDF page using iText? I have to display 12 bar codes in the same PDF page in three columns each one containing 4 bar codes (in other words it's 4 by 3 matrix).

Posted on StackOverflow on Feb 24, 2014 by user3323182

I've made a Barcodes example that does exactly what you need. See the resulting pdf: barcodes_table.pdf

There's nothing difficult about it. You just create a table with 4 column and you add 12 cell:

PdfPTable table = new PdfPTable(4);
for (int i = 0; i 

The createBarcode() method creates a cell with a barcode:

public static PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException {
    BarcodeEAN barcode = new BarcodeEAN();
    PdfPCell cell = new PdfPCell(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true);
    return cell;

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now