How to introduce a rowspan?

I am adding a table to a PDF file. I have 3 rows and 3 columns. I want the first column to appear only once as a single cell for all the rows. The result should be like where it says Deloitte in the column of company as shown in the image:

Table showing desired result

Posted on StackOverflow on Apr 5, 2014 by sindhu jampani

The MyFirstTable example from iText in Action does exactly what you need. It looks like this:

// a table with three columns
        Table table = new Table(UnitValue.createPercentArray(3)).useAllAvailableWidth();
        // the cell object
        Cell cell;
        // we add a cell with colspan 3
        cell = new Cell(1, 3).add(new Paragraph("Cell with colspan 3"));
        table.addCell(cell);
        // now we add a cell with rowspan 2
        cell = new Cell(2, 1).add(new Paragraph("Cell with rowspan 2"));
        table.addCell(cell);
        // we add the four remaining cells with addCell()
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");

In your case you'd need cell = new Cell(1,6); for the cell with value Deloitte.

Click this link if you want to see how to answer this question in iText 5.



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
Contact

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