Hello Paulo,
I now wrote a work-around for my problem. Well it's not really a workaround, I
just added my header-content to the document directly because it's not likely
that I have more than one page. Still not really satisfying.
BUT: I just looked over my code again, and in fact somewhere in the content I
DO add a PdfPTable to a paragraph.. and it works fine!
So maybe there is a bug? Or it has to be a table alone with no other paragraphs
nested? It shouldn't be related to the HeaderFooter, because the exception was
thrown when I added the table.
I don't know why it works fine here:
Paragraph diagTableP = new Paragraph();
PdfPTable diagTable = new PdfPTable(3);
diagTable.setWidthPercentage(100);
int[] widths = {28, 1, 71};
diagTable.setWidths(widths);
diagTable.setSpacingBefore(0);
diagTable.setSpacingAfter(0);
diagTable.getDefaultCell().setBorder(0);
{
Paragraph dots = new Paragraph(":", FONT1);
dots.setAlignment(Paragraph.ALIGN_LEFT);
diagTable.addCell(new Paragraph("Text 1.1",
FONT1));
diagTable.addCell(dots);
diagTable.addCell(new Paragraph("text 1.3,
FONT1));
diagTable.addCell(new Paragraph("text 2.1",
FONT1));
diagTable.addCell(dots);
diagTable.addCell(new Paragraph("text 2.3",
FONT1));
}
diagTableP.add(diagTable);
doc.add(diagTableP);
ciao
M. Baumann
On 12.08.2008 16:13, Paulo Soares psoares-at-glintt.com |iText Mailinglist|
wrote:
> PdfPTable can't be added to a Paragraph.
>
> Paulo
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On
>> Behalf Of [EMAIL PROTECTED]
>> Sent: Tuesday, August 12, 2008 2:57 PM
>> To: [email protected]
>> Subject: [iText-questions] IndexOutOfBoundsException at
>> Paragraph.add(Unknown Source)
>>
>> 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;
>
>
> Aviso Legal:
>
> Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
> informação confidencial ou legalmente protegida. A incorrecta transmissão
> desta mensagem não significa a perca de confidencialidade. Se esta mensagem
> for recebida por engano, por favor envie-a de volta para o remetente e
> apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o
> destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.
>
>
>
> Disclaimer:
>
> This message is destined exclusively to the intended receiver. It may contain
> confidential or legally protected information. The incorrect transmission of
> this message does not mean the loss of its confidentiality. If this message
> is received by mistake, please send it back to the sender and delete it from
> your system immediately. It is forbidden to any person who is not the
> intended receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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