Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Fwd: Cannot nesting a table within a list item

Dhruba Bandopadhyay

2007-06-22

Replies:

Hi,

May I request any further feedback on this question of mine? Is it
just me or is there a different usage of this? Has anyone run the
junit test?

Many thanks.

---------- Forwarded message ----------
From: Dhruba Bandopadhyay <bdhruba@(protected)>
Date: Jun 22, 2007 11:44 AM
Subject: Cannot nesting a table within a list item
To: Post all your questions about iText here
<iText-questions@(protected)>


Hi,

I have a junit test which fails with an exception. I would much like
your advice on how to get this to work. How can I represent this html
in itext? It works if I add the table directly to the document.

Exception:

java.lang.RuntimeException: list {[Rectangle: 80.0x0.0 (rot: 0
degrees)]} could not add li {[Rectangle: 80.0x0.0 (rot: 0 degrees)]}
    at com.foo.dc.consumer.itext.AddTableToList.test(AddTableToList.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke (Method.java:597)
    at junit.framework.TestCase.runTest (TestCase.java:164)
    at junit.framework.TestCase.runBare (TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected (TestResult.java:128)
    at junit.framework.TestResult.run (TestResult.java:113)
    at junit.framework.TestCase.run (TestCase.java:120)
    at junit.framework.TestSuite.runTest (TestSuite.java:228)
    at junit.framework.TestSuite.run (TestSuite.java:223)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java:196)



Html:

<html>
<body>
<table>
  <tr>
    <td>
    <ol>
       <li>
       <table>
          <tr>
            <td>foo</td>
            <td>bar</td>
          </tr>
       </table>
       </li>
    </ol>
    </td>
  </tr>
</table>
</body>
</html>

Java:

package com.foo.dc.consumer.itext;

import java.io.FileOutputStream;

import junit.framework.TestCase;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.List;
import com.lowagie.text.ListItem;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.rtf.RtfWriter2;

public class AddTableToList extends TestCase {

  public void test() throws Exception {

    Document document = new Document();

    PdfWriter.getInstance(document, new FileOutputStream("/tmp/tmp.pdf"));
    RtfWriter2.getInstance(document, new FileOutputStream("/tmp/tmp.rtf"));

    document.open();

    // create a table with two columns
    Table table = new Table(1);

    // create four cells
    table.addCell(new Cell("foo"));
    table.addCell(new Cell("bar"));

    // create a list
    List list = new List();

    // create a list item
    ListItem li = new ListItem();

    // try to add the table to the list item
    if (!li.add(table)) {
       throw new RuntimeException("li {" + li + "} could not add
table {" + table + "}");
    }

    // try to add the list item to the list
    if (!list.add(li)) {
       throw new RuntimeException("list {" + li + "} could not
add li {" + li + "}");
    }

    document.add(list);

    document.close();

  }

}

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
©2008 junlu.com - Jax Systems, LLC, U.S.A.