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
[email protected]
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/

Reply via email to