Docx document saved with latest aspose java jar open with compatibility mode

Hi,
We are using aspose for word document modification. But recently we updated our aspose jar from 13.3 to 15.12. After updating to the latest jar we are facing a issue with all docx are open in compatibility mode. Please find the sample code below:

public static void main(String[] args) throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln(“1) section 1”);
builder.writeln(“1.1) abcdEFG”);
builder.writeln(" asdasd asdas das dasd “);
builder.writeln(” sa da das ");
OutputStream outStream = new ByteArrayOutputStream();
OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL);
doc.save(outStream, ooxmlSaveOptions);
byte[] bytesInDoc = ((ByteArrayOutputStream) outStream).toByteArray();
FileOutputStream fileOutputStream = new FileOutputStream(new File(“D:\output.docx”));
fileOutputStream.write(bytesInDoc);
}

This code is working properly with the old jar. But for some other fixes available in the newer version, we can not use the old jar anymore.
So we need a solution for this problem as soon as possible.

Thanks
Reetam

Hi Reetam,


Thanks for your inquiry. Please add the following line in your code:

Document doc = new Document();
DocumentBuilder builder =
new DocumentBuilder(doc);
builder.writeln(
“1) section 1”);
builder.writeln(
“1.1) abcdEFG”);
builder.writeln(
" asdasd asdas das dasd “);
builder.writeln(
” sa da das ");
OutputStream outStream =
new ByteArrayOutputStream();
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2013);
OoxmlSaveOptions ooxmlSaveOptions =
new OoxmlSaveOptions();
ooxmlSaveOptions.setCompliance(OoxmlCompliance.
ISO_29500_2008_TRANSITIONAL);
doc.save(outStream, ooxmlSaveOptions);
byte[] bytesInDoc = ((ByteArrayOutputStream) outStream).toByteArray();
FileOutputStream fileOutputStream =
new FileOutputStream(new File(“D:\output.docx”));
fileOutputStream.write(bytesInDoc);

Hope, this helps.

Best regards,

Hi
Thank you very much for the quick reply. Your solution is working perfectly.

Thanks and Regards
Reetam