I added a Paragraph with a PdfPTemplate into a PdfPCell and after that I
changed the color of the PdfPCell. The result was that I did't see the content
of the template in the cell.
Any help welcome!
Code example:
Testclass:
public class Test {
public static void main(String[] args)
{
Document document = new Document(PageSize.A4, 50, 50, 70, 70);
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("test.pdf"));
writer.setPageEvent(new TestEvent());
document.open();
PdfPTable table = new PdfPTable(1);
Chunk chunk = new Chunk(" ");
chunk.setGenericTag("test");
Phrase phrase = new Phrase();
phrase.add(chunk);
Paragraph paragraph = new Paragraph();
paragraph.add(phrase);
PdfPCell cell = new PdfPCell(paragraph);
cell.setBackgroundColor(new Color(0,255,0));
table.addCell(cell);
document.add(table);
document.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
Testevent:
public class TestEvent extends PdfPageEventHelper {
PdfTemplate tpl;
BaseFont font;
public void onGenericTag(PdfWriter pdfWriter, Document document, Rectangle
rectangle, String string) {
PdfContentByte cb = pdfWriter.getDirectContent();
tpl = cb.createTemplate(10, 10);
cb.addTemplate(tpl, rectangle.left(), rectangle.bottom());
}
public void onCloseDocument(PdfWriter pdfWriter, Document document) {
try {
font = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
String text = "" + (pdfWriter.getPageNumber() - 1);
float fontSize = 10;
tpl.beginText();
tpl.setFontAndSize(font, 10);
tpl.setTextMatrix(0, 0);
tpl.showText(text);
tpl.endText();
} catch (Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/