Protect Document - Formatting Restrictions

In Word 2003 MS added a protection for formatting. I see in the Aspose.Words API how to implement the Editing Restrictions but not the formatting restrictions. Am I missing something or is this not an option?

Hi,

Applying formatting restrictions separately from editing restrictions is not allowed. However, when you protect the document from being edited, you also protect it from being formatted. Do you need to apply formatting protection only?

Yes in this case we would want to apply formatting protection only. I know I can do this within Office 2003 & Office 2007.

Thank you,

Andrew

I have logged your request as #1486, thank you for that. Sorry cannot say when this feature will be available.

@DmitryV , @Andrew.Crowder Something new about this issue? I need use Formatting Restrictions too.

@lu.ba Unfortunately, implementation of this feature has been postponed due it’s low demand. Your request is only the third one since the first request of this feature 17 years ago.

User @DmitryV wrote “However, when you protect the document from being edited, you also protect it from being formatted.”. But today I used document.Protect(ProtectionType.AllowOnlyRevisions, “psw”); and formating restrictions was unchecked. So how can I lock word styles editing?

@lu.ba I suppose Dmitry meant ProtectionType.ReadOnly. In this case the document is protected from editing and as a result from formatting too.

OK so I have to use another library for set “formating protection”. For example DocumentFormat.OpenXml. Because I need add one attribute w:formatting=“1” to documentProtection tag. Paid library Aspose can not do that. Fine. Thanks.

@lu.ba As I have mentioned the feature has very low demand, so it was not implemented. Though Aspose.Words preserves these document protection options upon document processing.

If someone need lock formating…use library DocumentFormat.OpenXml (after set protection by Aspose).

Example

var document = new Aspose.Words.Document(stream);

document.Protect(ProtectionType.AllowOnlyRevisions, "password");
//Save to memstream
MemoryStream fileToUpload = new();
document.Save(fileToUpload, SaveFormat.Docx);
//lock styles
WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileToUpload, true);
DocumentProtection dp =
    wordDoc.MainDocumentPart.DocumentSettingsPart
    .Settings.ChildElements.First<DocumentProtection>();

dp.Formatting = true;
wordDoc.Save();

@lu.ba Thank you for sharing your solution.