Aspose.Words for Java 2.1

Hi there,
We are using Aspose.Words for Java 2.1 and i just wanted to know if anyone can help a couple of questions:

  1. does the product work with Word 2007 documents (currently works fine with Word 2003 documents)?
  2. we have a word document that has a header that we currently populate with data from a db (and that functionality works fine). However, we want to take a step farther and lock down the header so users can’t update it by accident (since it is an automated process) but allow Aspose to modify it. Is that possible? If so, how?

Thanks in advance for your help!

Hi

Thanks for your inquiry. Aspose.Words for Java supports DOCX format starting from 2.6.0 version. You can download the latest version of Aspose.Words for Java from here:
https://releases.aspose.com/words/java
Regarding the second question, you can do it the following way:

  1. Create an empty section with Header.
  2. Fill this header with data.
  3. Protect this section.

All other sections should inherit header from the first section.
Please try using the following code:

// Open template
Document doc = new Document("C:\\Temp\\in.docx");
doc.getMailMerge().execute(new String[] { "Header" }, new Object[] { "MyProtectedHeader" });
// Section protection only works when document protection is turned and only editing in form fields is allowed.
doc.protect(ProtectionType.ALLOW_ONLY_FORM_FIELDS);
// By default, all sections are protected, but we can selectively turn protection off.
doc.getSections().get(0).setProtectedForForms(false);
doc.save("C:\\Temp\\out.docx");

Please see the attached in.docx and output out.docx.
Best regards,

Thank you Andrey for your quick response. I will try it and let you know.

Andrey,
We have been asked to password protect the locked header. Can Aspose (v2.1) handle unlocking a password protected section and locking it again? If so, how would the above code change?
Thanks again for your help.

Hi

Thanks for your request. To password protect your document header, you should little bit change your code:

doc.protect(ProtectionType.ALLOW_ONLY_FORM_FIELDS, "password");

to unprotect you should use the following line of code:

doc.unprotect();

Best regards,