Hello,
I am trying to add a header to my PDF, but get the following exception (source
code see end of this mail:
Exception in thread "PDF Creation" java.lang.IndexOutOfBoundsException: Index:
4, Size: 4
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.lowagie.text.Paragraph.add(Unknown Source) (...)
I really don't know what exactly is causing this, does anyone have an idea? If
I only add the first to paragraphs to my header it works, but the table does
not! I'm thankful for any help or advice.
Code:
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.setSpacingBefore(0);
table.setSpacingAfter(0);
table.getDefaultCell().setBorder(0);
table.getDefaultCell().setNoWrap(true);
Paragraph headerP = new Paragraph();
Paragraph headerP2 = new Paragraph();
headerP.add(new Paragraph("text1"), FONT1));
headerP.add(new Paragraph("text2", FONT1));
{
PdfPCell cell = new PdfPCell(table.getDefaultCell());
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setUseAscender(true);
Paragraph leftP = new Paragraph("tabletext1", FONT2);
leftP.setAlignment(Paragraph.ALIGN_LEFT);
cell.addElement(leftP);
table.addCell(cell);
}
{
Paragraph rightP = new Paragraph();
PdfPCell cell = new PdfPCell(table.getDefaultCell());
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.setUseAscender(true);
rightP.setAlignment(Paragraph.ALIGN_RIGHT);
rightP.add(new Paragraph("tabletext2.1", FONT2));
rightP.add(new Paragraph("tabletext2.2", FONT2));
rightP.add(new Paragraph("tabletext2.3, FONT2));
cell.addElement(rightP);
table.addCell(cell);
}
headerP2.add(table);
headerP.add(headerP2);
return headerP;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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