Page 1 of 1

VariablePrepare cause trouble in a new doc

PostPosted: Mon Jun 19, 2017 7:26 pm
by ClementCvl
Hi,

Sorry Jason I duplicate my topic from Stackoverflow: https://stackoverflow.com/questions/44458760/docx4j-variable-prepare-cause-trouble-when-open-a-saved-docx but I will add more info here.

So I need to use variablePreapre() to regroup my variable (they look like that: $variable$), and when I open my new docx there is a Word error:

We're sorry. We can't open result.docx because we found a problem with its contents.
The XML data is invalid according to the schema.
Location: Part:/word/document.xml, Line: 0, Column: 0


But Word can repear easily, so it's not a big problem.

After that I tried with a blank document, juste created and saved without any change the document is attached at this post (test.docx).

This is my code:
Code: Select all
WordprocessingMLPackage wordMLPackage = Docx4J.load(new File(directory+fileName));
VariablePrepare.prepare(wordMLPackage);
wordMLPackage.save(new java.io.File("result.docx") );


And I attach also the created docx at this post (result.docx).

At the end I try my code without the
Code: Select all
VariablePrepare.prepare(wordMLPackage)
, and it work without problem.

I don't know how to fix it, at the beginning I think the problem was my variable but it doesn't work with the any document ..

Thank's you for your help

Re: VariablePrepare cause trouble in a new doc

PostPosted: Mon Jun 19, 2017 11:08 pm
by jason
On a quick look, the problem is @mc:Ignorable includes "w16cid", but there is no namespace declaration output for that.

Compare the input docx, which declares xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"

I'll fix this tomorrow.

Re: VariablePrepare cause trouble in a new doc

PostPosted: Tue Jun 20, 2017 1:13 pm
by jason

Re: VariablePrepare cause trouble in a new doc

PostPosted: Tue Jun 20, 2017 5:58 pm
by ClementCvl
Thank's you, how can I add it to my project ? I use maven to get DOCX4J, and I don't know how to add your changes

Re: VariablePrepare cause trouble in a new doc

PostPosted: Mon Jun 26, 2017 10:16 pm
by jason
You can build it from source (mvn install).

Or wait for a nightly build, then use maven to put that in your local repo.

Re: VariablePrepare cause trouble in a new doc

PostPosted: Tue Jul 11, 2017 8:04 pm
by Marimuthu
I have created new docx4j-3.3.6-snapshot jar and used this dependency for my program. If I save the document from code without editing anything, it is opening document properly. But after replacing something on the template then MS word 2010 displaying error. This is the error which got while opening the docx, 'The file output.docx cannot be opened because there are some problems with the contents'. But I am able to open same docx with wordpad.

Re: VariablePrepare cause trouble in a new doc

PostPosted: Wed Jul 12, 2017 7:36 am
by jason
docx4j 3.3.5 fixes (should fix) the problem the original poster had; see further announces/docx4j-3-3-5-released-t2583.html

So try that. If you are still having problems, please post the problematic docx.