I am generating pdf file from database using itext pdf library.Now my need i that i have to show alternative rows of pdf table in different colour just like zebra colour (grey and white) but i dont know how to do that...
Here is my code..
PdfPTable table = new PdfPTable(10);
table.setTotalWidth(100);
table.setWidthPercentage(100);
while (rs.next()) {
table.addCell(rs.getString("date"));
table.addCell(rs.getString("time"));
table.addCell(rs.getString("source"));
table.addCell(rs.getString("destination"));
table.addCell(rs.getString("extension"));
}
Please help me. Thanks in advance.
boolean b = true;
for(PdfPRow r: table.getRows()) {
for(PdfPCell c: r.getCells()) {
c.setBackgroundColor(b ? BaseColor.GREY : BaseColor.WHITE);
}
b = !b;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With