First I added a Paragraph with some Chuncks into a PdfPCell. In the
method "cellLayout" I created a PdfTemplate. The coordinates for the
PdfTemplate came from the Chunk object in the Paragraph. I saved them in
the "onGericTag" method.
Now I changed the rotation of the PdfPCell and the problem was, that the value
of the PdfTemplate appeared at the end of the page and not in the cell. I
believe that the coordinates for the PdfTemplate are wrong after the rotation.
The problem is, that the Chunk is in the Paragraph and I can't change his
coordinates.
Any help welcome!
Example code:
public class Test {
public static void main(String[] args)
{
try {
Document document = new Document(PageSize.A4, 50, 50, 70, 70);
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("c:\\test.pdf"));
TestEvent te = new TestEvent();
writer.setPageEvent(te);
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.setCellEvent(te);
cell.setBackgroundColor(new Color(0,255,0));
cell.setRotation(90);
table.addCell(cell);
document.add(table);
document.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
public class TestEvent extends PdfPageEventHelper implements PdfPCellEvent {
PdfTemplate tpl;
BaseFont font;
Rectangle tagPosition;
public void onGenericTag(PdfWriter pdfWriter, Document document, Rectangle
rectangle, String string) {
tagPosition = rectangle;
}
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();
}
}
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[]
canvases) {
PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
tpl = cb.createTemplate(10, 10);
cb.addTemplate(tpl, tagPosition.left(), tagPosition.bottom());
}
}
-------------------------------------------------------------------------
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/