Page 1 of 1

Recreate docx using the openxml paragraph node.

PostPosted: Mon Sep 23, 2013 9:36 pm
by broshni
Hi Jason / Admin
Before I place my query here, let me put in brief what I have done so far.
I have iterated over the content controls (W:SDT) and converted the contents in HTML and successfully saved into database. For this process, I have used openxml4j and xpath to iterate over each node and generate appropriate html.
Now I have been asked to re-create a docx out of the html which I have saved in database. In this regard, I have introduced one more column in the table(database) so that I can insert the openxml which would help me in generating the docx.
Here is the issue i find difficult to re-create the docx from the openxml.
My sample openxml ( toString) is as follows:

Code: Select all
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" w:rsidP="0086466A" w:rsidR="0086466A" w:rsidRDefault="0086466A">
<w:r>
<w:t xml:space="preserve">What is the area of a circle whose radius is 5 </w:t>
</w:r>
<w:proofErr w:type="gramStart"/>
<w:r>
<w:t>cm ?</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
<w:r>
<w:t xml:space="preserve"> </w:t>
</w:r>
<m:oMath xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>A=π</m:t>
</m:r>
<m:sSup>
<m:sSupPr>
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
</m:ctrlPr>
</m:sSupPr>
<m:e>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>r</m:t>
</m:r>
</m:e>
<m:sup>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>2</m:t>
</m:r>
</m:sup>
</m:sSup>
</m:oMath>
</w:p>


Java code to generate the docx :
Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addObject(XmlUtils.unmarshalString(openxmlString));//Paragraph node toString().
wordMLPackage.save(new java.io.File("output filepath"));

It is generating the docx but pi becomes unrecognised and replaced by ?. I hope you' have got what I meant to say.
How do I solve this?
Pls help

Re: Recreate docx using the openxml paragraph node.

PostPosted: Mon Sep 23, 2013 10:36 pm
by broshni
Pls find the attached docx from which I have used to retrieve the openxml Paragraph node and output docx.

Re: Recreate docx using the openxml paragraph node.

PostPosted: Mon Sep 30, 2013 8:22 am
by jason
Sounds like the encoding is getting messed up somewhere between saving to the database, and setting your openxmlString

Re: Recreate docx using the openxml paragraph node.

PostPosted: Thu Oct 03, 2013 6:28 am
by broshni
Jason ;

Even if I copied the oMath xml part from the document.xml and tried to create the docx . It is still missing
Code: Select all
PI
sign.

Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addObject(XmlUtils.unmarshalString(openxmlString));//Paragraph node toString().
wordMLPackage.save(new java.io.File("output filepath"));


Please check the above attached files for reference.