Hi Howard,
Many thanks for your tips!
I managed to do it, replacing the PdfPTable with a Table object and not using
chunks!
Seems to me that the chunk object is causing this ClassCastException when
converting tables.
Again, many thanks!
Rico
PS: here is how I did it:
Table table = new Table(2);
table.setBorder(Table.NO_BORDER);
table.setWidth(100);
Cell cell;
if(iLeft!= null){
cell = new Cell(iLeft);
} else {
cell = new Cell(" ");
}
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
cell.setBorder(Cell.NO_BORDER);
table.addCell(cell);
Paragraph p = new Paragraph(" ");
p.setAlignment(Paragraph.ALIGN_RIGHT);
cell = new Cell(p);
if(iRight!=null) {
cell.addElement(iRight);
}
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
cell.setBorder(Cell.NO_BORDER);
table.addCell(cell);
RtfHeaderFooter headerFooter = new RtfHeaderFooter(table);
writer.setHeader(headerFooter);
From: Howard Shank [mailto:hgsh...@yahoo.com]
Sent: segunda-feira, 15 de Junho de 2009 18:41
To: Post all your questions about iText here
Subject: Re: [iText-questions] RtfMapper problem mapping a table cell with a
image paragraph
RTF unfortunately relies mainly on the deprecated Table object. PdfPTable is
not fully implemented and has unexpected results depending on the type of
element inserted in a table. Sometimes the elements are not inserted inside the
table, but trail after the table or outside the properly table tag elements.
I do not have a solution for you at this time. Perhaps someone else has found a
work around for this case?
Regards,
Howard Shank
_____
From: Luís Tiago Rico <tiagor...@gmail.com>
To: iText-questions@lists.sourceforge.net
Sent: Monday, June 15, 2009 1:07:14 PM
Subject: [iText-questions] RtfMapper problem mapping a table cell with a image
paragraph
Hi to all,
I want to create a RTF document header with a PdfPTable containing two images,
one aligned to left and the other aligned to the right.
But when I try to add the image to a Paragraph Object (as a Chunk element) for
having the correct alignment I have a class cast exception…..
ERROR [DefaultExceptionHandler] com.lowagie.text.pdf.PdfPTable cannot be cast
to com.lowagie.text.SimpleTable
java.lang.ClassCastException: com.lowagie.text.pdf.PdfPTable cannot be cast to
com.lowagie.text.SimpleTable
at com.lowagie.text.rtf.RtfMapper.mapElement(Unknown Source)
If I exclude the chunk element from the paragraph all works as expected! I took
a look at the svn source but found no clue on this.
My code is bellow (note that I call some other methods that I exclude here as
they do not influence the error)
I’m using iText 2.1.5 version!
…
Image iRight = headerRight;
iRight.scaleAbsoluteWidth(100);
iRight.scaleAbsoluteHeight(iRight.getHeight() / iRight.getWidth() * 100);
iRight.setAlignment(Image.ALIGN_RIGHT);
…
PdfPTable table = createTable(2); //some calling method creates a table with 2
cells
PdfPCell cell = iLeft!= null ? createImageCell(iLeft, true, 0, 0) :
createPhraseCell(new Phrase(""), 0, 0); //some calling methods also
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
table.addCell(cell);
if(iRight!=null) {
Paragraph p = new Paragraph("In the right");
p.add(new Chunk(iRight, 0, 0)); //If I delete this line all
works
p.setAlignment(Paragraph.ALIGN_RIGHT);
cell = buildCell(new PdfPCell(p),0,0); //another calling method
} else{
cell = createPhraseCell(new Phrase(""), 0, 0); //another
calling method
}
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
RtfHeaderFooter headerFooter = new RtfHeaderFooter(table);
writer.setHeader(headerFooter);
Is there any way I can achieve this using a table? What would be a better way
to achieve this?
Thanks in advance
Rico
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/