Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Itext: Set border colors to a table

PdfPCell class provides following methods to Set Border color.

public Void setBorderColor(final BaseColor borderColor)
public void setBorderColorLeft(final BaseColor borderColorLeft)
public void setBorderColorRight(final BaseColor borderColorRight)
public void setBorderColorTop(final BaseColor borderColorTop)
public void setBorderColorBottom(final BaseColor borderColorBottom)

Following is the complete working application.

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class TestTable {
private static final String fileName = "/Users/harikrishna_gurram/Documents/itext/tableEx.pdf";

public static void main(String args[]) throws DocumentException, MalformedURLException, IOException {

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(fileName));
document.open();

PdfPTable table = new PdfPTable(2);

PdfPCell cell = new PdfPCell();
cell.setBorderColor(BaseColor.GREEN);
cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

cell.setPhrase(new Phrase("Number"));
table.addCell(cell);

cell.addElement(new Phrase("Square"));
table.addCell(cell);

for (int i = 1; i 11; i++) {
cell.setPhrase(new Phrase(Integer.toString(i)));
table.addCell(cell);

cell.setPhrase(new Phrase(Integer.toString(i * i)));
table.addCell(cell);
}

document.add(table);

document.close();
}
}



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Itext: Set border colors to a table

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×