Saving document to support Office 2013 and 2016 without compatibility issues

Hi,


We are using ASPOSE mainly to apply watermark, turning on/off track changes and updating the custom document properties values. Some of our users are using office 2013 & 2016. We noticed that with ASPOSE default save option doesn’t automatically use the word version (i.e. if word is created with 2013, it doesn’t save to 2013 format) unless we specify the ooxmlcompliance settings.
My questions:
1) Do we always need to use the ooxmlcompliance options to save to 2013 or 2016 versions?
like: OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);

2) I understand we need to use optimizefor option for watermarks. Do we need to use this for other operations like updating doc properties, track changes etc…?
Document doc = new Document(ipfile);
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2007);

3) Is it always MsWordVersion.WORD_2007? or can we set WORD_2013 for other operations like updating doc properties, track changes etc…

Hi Mahesh,

Thanks for your inquiry.
pinnamanenim:
1) Do we always need to use the ooxmlcompliance options to save to 2013 or 2016 versions?
like: OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
Yes, your understanding is correct.
pinnamanenim:
2) I understand we need to use optimizefor option for watermarks. Do we need to use this for other operations like updating doc properties, track changes etc..?
Document doc = new Document(ipfile);
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2007);
3) Is it always MsWordVersion.WORD_2007? or can we set WORD_2013 for other operations like updating doc properties, track changes etc..
No. This solution is only for watermark issue. Please check my reply here.

You may use following code to insert watermark into the document. This code example converts the WordArt shape into image. In this case, you do not need to use OptimizeFor and OoxmlSaveOptions.setCompliance methods. Hope this helps you.


private static void insertWatermarkText(Document doc, String watermarkText) throws Exception {

DocumentBuilder builder =
new DocumentBuilder(doc);
// Create a watermark shape.
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);

// Set up the text of the watermark.
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily(
"Times New Roman");
watermark.setWidth(
500);
watermark.setHeight(
100);
// Text will be directed from the bottom-left to the top-right corner.
watermark.setRotation(-40);
// Remove the following two lines if you need a solid black text.
watermark.getFill().setColor(Color.GRAY); // Try LightGray to get more
// Word-style watermark
watermark.setStrokeColor(Color.GRAY); // Try LightGray to get more
// Word-style watermark

// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.
PAGE);
watermark.setWrapType(WrapType.
NONE);
watermark.setVerticalAlignment(VerticalAlignment.
CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.
CENTER);

ShapeRenderer shapeRenderer = watermark.getShapeRenderer();
Shape shape;

ByteArrayOutputStream outputStream =
new ByteArrayOutputStream();
ImageSaveOptions saveOptions =
new ImageSaveOptions(SaveFormat.PNG);
shapeRenderer.save(outputStream, saveOptions);
shape = builder.insertImage(outputStream.toByteArray());

shape.setWrapType(WrapType.
NONE);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.
PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.
CENTER);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.
PAGE);
shape.setVerticalAlignment(VerticalAlignment.
CENTER);

// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(shape);


// Insert the watermark into all headers of each document section.
for (Section sect : doc.getSections()) {
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.
HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.
HEADER_EVEN);
}
}

Thank you very much Tahir.