I have a table where its cells background are partially transparent. The
cells' background are set using a CellEvent (see
http://www.nabble.com/Different-transparency-for-cells-in-PdfPtable-td21511310.html).
However, there is a border drawn for the cells even when I set the
borderWidth and border to 0. How do I get rid of this border?
Please see example program below:
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfGState;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
public class TestTableBorder extends PdfPageEventHelper {
private static final long serialVersionUID = -6033026500372479591L;
private static Color COLOR_MEDIUM_BLUE = new Color(0, 122, 201);
private static String TEXT_FONT_NAME = "Verdana";
private Document document = null;
private PdfWriter writer = null;
private OutputStream output;
private CellBgEvent cellBgEvent = null;
private PdfGState documentGs = new PdfGState();
public static void main(String[] args) {
try {
String outfile = "testTableBorder.pdf";
FileOutputStream out = new FileOutputStream(outfile);
new TestTableBorder(out);
out.close();
} catch (Exception e) {
System.err.println("document: " + e.getMessage());
}
}
public TestTableBorder(OutputStream out) throws DocumentException {
cellBgEvent = this.new CellBgEvent();
output = out;
document = new Document(PageSize.LETTER, 40, 40, 160, 50);
writer = PdfWriter.getInstance(document, output);
writer.setPageEvent(this);
document.open();
documentGs.setFillOpacity(0.8f);
documentGs.setStrokeOpacity(1f);
PdfPTable table;
table = createTable();
document.add(table);
document.close();
}
private PdfPTable createTable() throws DocumentException {
PdfPTable table = null;
PdfPCell cell;
int[] cols = { 50, 50 };
Phrase phrase;
try {
table = new PdfPTable(2);
table.setWidthPercentage(100);
table.setWidths(cols);
for (int i = 0; i < 6; i++) {
phrase = new Phrase(15, "data", FontFactory.getFont(TEXT_FONT_NAME,
10,
Font.NORMAL, Color.BLACK));
cell = new PdfPCell(phrase);
cell.setBorderWidth(0);
cell.setBorder(0);
cell.setHorizontalAlignment(Table.ALIGN_LEFT);
cell.setCellEvent(cellBgEvent);
table.addCell(cell);
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
}
return table;
}
class CellBgEvent implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle rect,
PdfContentByte[] canvas) {
try {
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.saveState();
cb.setGState(documentGs);
cb.setColorFill(COLOR_MEDIUM_BLUE);
cb.rectangle(rect.getLeft(), rect.getBottom(), rect.getWidth(), rect
.getHeight());
cb.fill();
cb.restoreState();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
--
View this message in context:
http://www.nabble.com/Table-cells-border-appear-evem-when-BorderWidth-is-set-to-0-when-background-is-transparent-tp21691359p21691359.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php