Page 1 of 1

Java 9 - docx4j v6.0.1 - Table missing from pdf

PostPosted: Tue Sep 11, 2018 9:13 pm
by adams
Hi Jason!

I have another (maybe) Java 9 specific error.
I have a DOCX file with a table, and there are tokens inside the table. (1 row, 3 cols -> 3 token)
I can replace the tokens with strings from code, which works very well.

I have the following code:
Code: Select all
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
ByteArrayOutputStream docxStream = new ByteArrayOutputStream();

try {
   Docx4J.toPDF(wordMLPackage, pdfStream);
   Docx4J.save(wordMLPackage, docxStream);
   pdfStream.flush();
   docxStream.flush();
   pdfStream.close();
   docxStream.close();
} catch (Docx4JException | IOException e) {
   throw new IOException("Error when generating byte array from document!", e);
}


If I save the docxStream to a file, it contains the table, but the pdf is empty.

(The pdf contains the same table with Java 8 compiled code.)

So I think it's a Java 9 problem, and maybe I'm missing something in my dependencies.

My dependency tree looks like this:
Code: Select all
dependencies {
    implementation('commons-io:commons-io:2.6')
    implementation('javax.xml.bind:jaxb-api:2.4.0-b180830.0359')
    implementation('org.docx4j:docx4j:6.0.1')
    implementation('org.docx4j:docx4j-export-fo:6.0.1')
    implementation('org.docx4j:docx4j-ImportXHTML:6.0.1')
    implementation('org.glassfish.jaxb:jaxb-core:2.3.0.1')
    implementation('org.glassfish.jaxb:jaxb-runtime:2.3.0.1')
    testImplementation('junit:junit:4.12')
}

Re: Java 9 - Table missing from pdf

PostPosted: Tue Sep 11, 2018 10:28 pm
by adams
If I open the saved DOCX with WordprocessingMLPackage.load(...); and generate a pdf from it, it's still empty.

Re: Java 9 - Table missing from pdf

PostPosted: Wed Sep 12, 2018 8:10 pm
by adams
Okay, I found something. If I use these dependencies:
Code: Select all
dependencies {
    implementation('commons-io:commons-io:2.6')
    implementation('javax.xml.bind:jaxb-api:2.4.0-b180830.0359')
    implementation('org.docx4j:docx4j:6.0.1')
    implementation('org.docx4j:docx4j-export-fo:3.3.6')
    implementation('org.docx4j:docx4j-ImportXHTML:6.0.1')
    implementation('org.glassfish.jaxb:jaxb-core:2.3.0.1')
    implementation('org.glassfish.jaxb:jaxb-runtime:2.3.0.1')
    testImplementation('junit:junit:4.12')
}

Then the generated pdf contains the table what i wanted.

Edit:
I made some test with different versions. The above dependencies were the newest working combination.

Re: Java 9 - docx4j v6.0.1 - Table missing from pdf

PostPosted: Thu Sep 13, 2018 8:45 am
by jason
Since what works for you is export-fo:3.3.6, that would suggest the problem is one of the 2 commits of 17 June: https://github.com/plutext/docx4j-expor ... its/master

Re: Java 9 - docx4j v6.0.1 - Table missing from pdf

PostPosted: Thu Sep 13, 2018 9:21 pm
by jason
Can you attach a docx exhibiting the issue?

Alternatively, you can inspect the FO file to see whether the table is present:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                        foSettings.setFoDumpFile(new java.io.File(inputfilepath + ".fo"));
 
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


and if so, whether its representation has changed.

Re: Java 9 - docx4j v6.0.1 - Table missing from pdf

PostPosted: Fri Sep 14, 2018 6:52 pm
by adams
Hi!

The .fo's content:
Code: Select all
<?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><layout-master-set xmlns="http://www.w3.org/1999/XSL/Format" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"><simple-page-master margin-bottom="12mm" margin-left="0.98in" margin-right="0.98in" margin-top="12mm" master-name="s1-simple" page-height="297mm" page-width="210mm"><region-body column-count="1" column-gap="12mm" margin-bottom="35.0pt" margin-left="0mm" margin-right="0mm" margin-top="35.0pt"/><region-before extent="0.0pt" region-name="xsl-region-before-simple"/><region-after extent="0.0pt" region-name="xsl-region-after-simple"/></simple-page-master><page-sequence-master master-name="s1"><repeatable-page-master-alternatives><conditional-page-master-reference master-reference="s1-simple"/></repeatable-page-master-alternatives></page-sequence-master></layout-master-set><fo:page-sequence force-page-count="no-force" id="section_s1" format="" master-reference="s1"><fo:flow flow-name="xsl-region-body">
 
  <fo:block font-size="11.0pt" line-height="107%" space-after="0.11in" white-space-treatment="preserve"> </fo:block>
 
 
 
  </fo:flow></fo:page-sequence></fo:root>

Re: Java 9 - docx4j v6.0.1 - Table missing from pdf

PostPosted: Thu Sep 20, 2018 10:09 am
by jason
Thanks for this; fixed at https://github.com/plutext/docx4j-expor ... efcf55b1a0

(ie in docx4j-export-FO)