Page 1 of 1

different BlockBox output with the same input string

PostPosted: Wed Apr 09, 2014 12:20 am
by supachamp
Hi,

I experience the following effect. I generate a Word document from an XHTML source. Using the same source string, one of my Java applications processes the content correctly and generates a nice Word document. My RCP application which processes exactly the same source string generates a different Word document where all formats are gone. I use the same code to generate the Word document in both applications:

Code: Select all
this.wordMLPackage = WordprocessingMLPackage.load(new File(TEMPLATE_WORD_DOCUMENT));

String htmlString = "<body></body>";

XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(this.wordMLPackage);
xHTMLImporter.setParagraphFormatting(FormattingOption.CLASS_TO_STYLE_ONLY);
xHTMLImporter.setRunFormatting(FormattingOption.CLASS_PLUS_OTHER);

this.wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(htmlString, ""));


After a long session of debugging, I have found out that the root cause of this problem is the BlockBox being returned from

Code: Select all
renderer.getRootBox();


in class XHTMLImporterImpl.java on line 659 (traverse(renderer.getRootBox(), null);).

In the simple example of "<body></body>";, the BlockBox returned by renderer.getRootBox(); is filled with

Code: Select all
BlockBox: <body> (block) (B) (0,0)->(13954 x 320))


in the Java application which generates the nice looking and well formated Word document. During the run of the RCP application, the following value is generated by renderer.getRootBox();:

Code: Select all
BlockBox: <body> (inline) (B) (0,0)->(15874 x 0)


How is this possible? I really use the same code in both applications.

I truly hope, that someone can help me out on that or at least point me into the right direction...

Best regards and thank you very much in advance!

Re: different BlockBox output with the same input string

PostPosted: Wed Apr 09, 2014 2:54 pm
by jason
Is it possible that you have multiple copies of XhtmlNamespaceHandler.css on your classpath, with differing content?

That file is in docx4j-ImportXHTML-3.0.1.jar

Re: different BlockBox output with the same input string

PostPosted: Wed Apr 09, 2014 10:16 pm
by supachamp
Thank you very much. I indeed had multiple versions of the docx4j-ImportXHTML jar on the classpath.