Let me explain (maybe Bruno understood what I was trying to say), try this 
code:



int mLeft = 40;

int mRight = 40;

int mTop = 50;

int mBottom = 50;

Document document = new Document(PageSize.A4, mLeft, mRight, mTop, mBottom);

PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream("xxx.pdf"));

document.open();



Font font1 = new Font(Font.COURIER, 10f);

Chunk text = new Chunk("one two three four five six seven eight nine ten ", 
font1);

MultiColumnText column = new MultiColumnText();



float[][] column1 = {

       {50,800,50,50},

       {200,800,200,700,150,600,200,500,200,50}

};

float[][] column2 = {

       {250,800,250,50},

       {500,800,500,50}

};



column.addColumn(column1[0], column1[1]);

column.addColumn(column2[0], column2[1]);



for (int i = 0; i < 100; i++) {

       column.addElement(text);

}

column.setAlignment(MultiColumnText.ALIGN_JUSTIFIED);

document.add(column);

document.close();





Until revision n.3637 by Bruno, the up code throws this exception:



com.lowagie.text.DocumentException: Irregular columns are not supported in 
composite mode.

       at com.lowagie.text.pdf.ColumnText.goComposite(ColumnText.java:1099)

       at com.lowagie.text.pdf.ColumnText.go(ColumnText.java:765)

       at com.lowagie.text.pdf.ColumnText.go(ColumnText.java:753)

       at 
com.lowagie.text.pdf.MultiColumnText.write(MultiColumnText.java:319)

       at com.lowagie.text.pdf.PdfDocument.add(PdfDocument.java:682)

       at com.lowagie.text.Document.add(Document.java:270)



If you changed the addColumn order adding column2 first and then column1, it 
worked but the right column in the page was filled first with a bad graphic 
effect!

With this revision the problem was solved and probably the correct bugfix 
was to change the simple parameter and not the addElement method.



However, now there's another problem adding line 305:

left[1] = documentY

from the second page on the left column disappeared!



Thank you

Leonardo



----- Original Message ----- 
From: "1T3XT info" <[email protected]>
To: "Post all your questions about iText here" 
<[email protected]>
Sent: Wednesday, December 31, 2008 9:43 AM
Subject: Re: [iText-questions] Bug inside MultiColumnText


> Leo wrote:
>> Hi everybody,
>> I found a bug into MultiColumnText class in method addElement.
>> The method should be written like this:
>>
>>   public void addElement(Element element) throws DocumentException {
>>   if (element instanceof Phrase) {
>>       columnText.addText((Phrase) element);
>>     } else if (element instanceof Chunk) {
>>       columnText.addText((Chunk) element);
>>     } else if (simple) {
>>       columnText.addElement(element);
>>     } else {
>>       throw new DocumentException("Can't add " + element.getClass() + "
>> to MultiColumnText with complex columns");
>>     }
>>   }
>>
>> Oherwise if you add a simple Chunk to an irregular column the method
>> throw the DocumentException but this is a mistake!!!
>
> Are you sure? Please explain.
> Currently the method looks like this:
>
> public void addElement(Element element) throws DocumentException {
>     if (simple) {
>         columnText.addElement(element);
>     } else if (element instanceof Phrase) {
>         columnText.addText((Phrase) element);
>     } else if (element instanceof Chunk) {
>         columnText.addText((Chunk) element);
>     } else {
>         throw new DocumentException("Can't add " + element.getClass() +
> " to MultiColumnText with complex columns");
>     }
> }
>
> If the columns are rectangular, YOU MUST use addElement. Using addText
> in this context, would lead to unexpected behavior when working in
> composite mode. That's why I think your "bugfix" introduces a bug,
> rather than solving one. As for the alleged bug: when using irregular
> columns, addText is used in case Phrases or Chunks are added. Please
> explain why you think an exception is thrown if element is an instance
> of chunk.
> -- 
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
> ------------------------------------------------------------------------------
> _______________________________________________
> 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
> 



------------------------------------------------------------------------------
_______________________________________________
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

Reply via email to