Page 1 of 1

HTML to Docx Feature Issues

PostPosted: Sat Jun 23, 2012 5:51 am
by nesteant
Please see html attached. It fails with the next exception
Code: Select all
Exception in thread "main" java.lang.RuntimeException: internal error
   at org.docx4j.org.xhtmlrenderer.render.Box.initContainingLayer(Box.java:472)
   at org.docx4j.org.xhtmlrenderer.newtable.TableBox.layoutRunningHeader(TableBox.java:326)
   at org.docx4j.org.xhtmlrenderer.newtable.TableBox.layoutChildren(TableBox.java:304)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
   at org.docx4j.org.xhtmlrenderer.newtable.TableBox.layoutTable(TableBox.java:282)
   at org.docx4j.org.xhtmlrenderer.newtable.TableBox.layout(TableBox.java:242)
   at org.docx4j.org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:61)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:947)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
   at org.docx4j.org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:61)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:947)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
   at org.docx4j.org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:61)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:947)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
   at org.docx4j.org.xhtmlrenderer.docx.DocxRenderer.layout(DocxRenderer.java:187)
   at org.docx4j.convert.in.xhtml.XHTMLImporter.convert(XHTMLImporter.java:214)
   at com.tinyreports.tinyrenderer.Test.main(Test.java:31)
   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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


execution class:
Code: Select all
public class Test {

   public static void  main(String[] args) throws Docx4JException, JAXBException {

      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
      XHTMLImporter.setHyperlinkStyle("Hyperlink");

      NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
      wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
      ndp.unmarshalDefaultNumbering();

      System.out.println(
            XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
      wordMLPackage.getMainDocumentPart().getContent().addAll(
            XHTMLImporter.convert(new File("d:/convert.html"), null, wordMLPackage) );
      wordMLPackage.save(new File("d:/html_output.docx") );
   }
}

Re: HTML to Docx Feature Issues

PostPosted: Sat Jun 23, 2012 9:24 am
by jason
Testing against git tip / latest docx4j nightly, for some reason the table related CSS confuses xhtmlrenderer.

Remove -fs-table-paginate: paginate from:

Syntax: [ Download ] [ Hide ]
Using css Syntax Highlighting
                table {
                        border-collapse: collapse;
                        margin: 5px 0;
                        -fs-table-paginate: paginate;
                }
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


and it works.

Looks like upstream issue http://java.net/jira/browse/XHTMLRENDERER-203