emichelli / flying-saucer

Automatically exported from code.google.com/p/flying-saucer
0 stars 0 forks source link

ClassCastException AnonymousBlockBox -> TableCellBox #144

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. ITextRenderer renderer = new ITextRenderer();
2. renderer.setDocumentFromString(pageHTML);
3. renderer.layout();

What is the expected output? What do you see instead?
Generated PDF. Exception

What version of the product are you using? On what operating system?
R8. Windows 7-64bit Sp1

Please provide any additional information below.
java.lang.ClassCastException: org.xhtmlrenderer.render.AnonymousBlockBox cannot 
be cast to org.xhtmlrenderer.newtable.TableCellBox
    at org.xhtmlrenderer.newtable.TableSectionBox.recalcCells(TableSectionBox.java:83)
    at org.xhtmlrenderer.newtable.TableBox.recalcSections(TableBox.java:198)
    at org.xhtmlrenderer.newtable.TableBox.calcMinMaxWidth(TableBox.java:153)
    at org.xhtmlrenderer.newtable.TableBox.layout(TableBox.java:215)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:293)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:271)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:89)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:925)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:805)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:293)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:271)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:89)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:925)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:805)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:293)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:271)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:89)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:925)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:805)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
    at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:209)

Original issue reported on code.google.com by wuwvibur...@googlemail.com on 19 Apr 2011 at 4:52

GoogleCodeExporter commented 8 years ago
We managed to eliminate the exception in our case by eliminating the "float: 
left;" in our css class definition.

The xhtml fragment that caused this exception (along with the css class 
definition)  in bigger html was:
  <div id="footer">
    <!-- ... -->
    <table>
      <tr>
        <td class="company">
          <ul>
            <li>text</li>
            <li>text</li>
            <li>text</li>
            <li>text</li>
            <li>text</li>
          </ul>
        </td>
        <!-- ... more td-s in here -->
        </td>
      </tr>
    </table>
  </div>

The "company" class definition from our css file:
#footer .company {float: left; clear: left; width: ;}

When we eliminated the "float: left;" then the exception didn't occurred any 
more.

Hopefully this helps others with this exception until the fix.

Original comment by jaanek...@gmail.com on 26 May 2011 at 5:18

GoogleCodeExporter commented 8 years ago
Thank you very much!

Original comment by wuwvibur...@googlemail.com on 31 May 2011 at 3:19

GoogleCodeExporter commented 8 years ago
yes "float" properties is the main culprit. Plz remove it and smile......

Original comment by shohan.c...@gmail.com on 15 Jun 2011 at 7:24

GoogleCodeExporter commented 8 years ago
This was failing on elements other than float:left.

Easiest code fix: 
Line 126 of BoxCollector.java, add a check to make sure that the container is 
of type TableBox before trying to cast given object.

Lines 126 and 127 (added "&& container instanceof TableBox"):
                    if (container.getStyle().isTable() && c instanceof RenderingContext && container instanceof TableBox) {  // HACK
                        TableBox table = (TableBox)container;

Exception: java.lang.ClassCastException: org.xhtmlrenderer.render.BlockBox 
incompatible with org.xhtmlrenderer.newtable.TableBox

Original comment by bates.ma...@gmail.com on 26 Jun 2012 at 6:39

GoogleCodeExporter commented 8 years ago
I was getting the same error as the previous comment. The above patch will 
block the class cast exception. Is there a reason it hasn't been added?

Original comment by philip.c...@gmail.com on 4 Aug 2012 at 7:35

GoogleCodeExporter commented 8 years ago
related to issue 162
related to issue 192
potential fix at https://github.com/flyingsaucerproject/flyingsaucer/pull/19

Original comment by robd...@gmail.com on 13 Nov 2012 at 7:24

GoogleCodeExporter commented 8 years ago
Are there any plans (and when) to provide a new version which includes the fix? 

Original comment by moritz.z...@gmail.com on 11 Jan 2013 at 8:00

GoogleCodeExporter commented 8 years ago
I'm also interested in a new release with this issue resolved. Any update plans 
for this?

Original comment by ch...@spinthewebb.com on 1 Feb 2013 at 11:58

GoogleCodeExporter commented 8 years ago
I am facing the same issue. Please fix it.

Original comment by ravi.kat...@gmail.com on 13 May 2014 at 6:25

GoogleCodeExporter commented 8 years ago
is this fixed? I am facing the same issue.

Original comment by suman.ja...@gmail.com on 29 Oct 2014 at 4:18