Cannot open docx in Open XML Tool after removing watermark

Hi,

I’m not sure what is wrong but when I remove a watermark from the document using ASPOSE, I cannot open it in Open XML SDK Tool. We use this tool very often to see the structure and/or debug issues but now we cannot use it.

Code to remove watermark:

    private static void RemoveWatermark(Document doc, String watermarkText) {
        NodeCollection headerColl = doc.getChildNodes(NodeType.HEADER_FOOTER, true);
        if (headerColl == null || headerColl.getCount() == 0)
            return;

        Node[] headerNodes = headerColl.toArray();
        int headerCount = headerNodes.length;
        for (int i = 0; i < headerCount; i++) {
            HeaderFooter header = (HeaderFooter) headerNodes[i];
            if (header.isHeader()) {
                NodeCollection shapeColl = doc.getChildNodes(NodeType.SHAPE, true);
                if (shapeColl.getCount() > 0) {
                    Node[] shapeNodes = shapeColl.toArray();
                    for (Node node : shapeNodes) {
                        if (node instanceof Shape) {
                            Shape shape = (Shape) node;
                            if (shape.getName().startsWith("MyWaterMark_")
                                    || shape.getTextPath().getText().equalsIgnoreCase(watermarkText)) {
                                shape.remove();
                            }
                        }
                    }
                }
            }
        }
    }

Thanks,

Mahesh

Looks like if I remove the ooxmlsaveoptions, then it opens fine.

I was using ooxmlSaveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);

Is there another way to save it to be compatible with Office 2013/2016?

Thanks,

Mahesh

Hi Mahesh,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15121. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Mahesh,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-15121) as ‘Not a Bug’.

The Open XML SDK 2.0 cannot read ISO/IEC 29500 Strict Format files. Starting from 2.5 Open XML SDK supports Strict Format. Please check the detail here:

https://docs.microsoft.com/en-us/office/open-xml/what-s-new-in-the-open-xml-sdk

pinnamanenim:

Is there another way to save it to be compatible with Office 2013/2016?

Please use Document.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2013) method. Hope this helps you.