Word API and confidentiality

We would like to integrate MS Word confidentiality available in Office 365 in our solution. I saw that in the ooxml standard there is a docMetadata folder and inside a LabelInfo.xml file. Is there an API available in the Java edition to create this?

@it.smartdocs

Cause

To integrate Microsoft Word confidentiality features available in Office 365, you need to work with the OOXML standard, specifically the docMetadata folder and the LabelInfo.xml file. However, there isn’t a direct API in Aspose.Words for Java that allows you to create this specific XML structure out of the box.

Solution

You can manipulate the document properties and metadata using Aspose.Words for Java, but creating a custom XML file like LabelInfo.xml will require you to handle it manually. You can create the XML structure and then embed it into the document as custom XML parts.

Code

Here’s a basic example of how to add custom XML parts to a document using Aspose.Words for Java:

import com.aspose.words.*;

public class AddCustomXmlPart {
    public static void main(String[] args) throws Exception {
        // Load your document
        Document doc = new Document("input.docx");

        // Create a custom XML part
        String xmlContent = "<LabelInfo><Confidentiality>High</Confidentiality></LabelInfo>";
        CustomXmlPart customXmlPart = new CustomXmlPart();
        customXmlPart.setXml(xmlContent);
        customXmlPart.setId("LabelInfo");

        // Add the custom XML part to the document
        doc.getCustomXmlParts().add(customXmlPart);

        // Save the document
        doc.save("output.docx");
    }
}

Next Steps

  1. Modify the xmlContent string to include the necessary confidentiality information as per your requirements.
  2. Test the document in Microsoft Word to ensure that the confidentiality settings are recognized.
  3. If needed, explore additional properties and methods in the Aspose.Words API to further customize the document.

If you have any further questions or need additional assistance, feel free to ask!