Skip to content

StartEnforcingProtection

Restricts how the document can be edited when it is opened in a word processor.

1
myDocumentProtection.StartEnforcingProtection(type: ( "NoChanges" | "Comments" | "FillingForms" | "TrackedChanges" ), password?: string):void

Parameters

( "NoChanges" | "Comments" | "FillingForms" | "TrackedChanges" ) type
    The restriction: 'NoChanges' (read only), 'Comments', 'FillingForms' or 'TrackedChanges'.

string password optional
    The password needed to remove the restriction. Defaults to no password.

Remarks

The restriction is saved in DOCX output. It is an editing restriction, not encryption: the content remains readable, and the password only prevents casual removal of the restriction.

Examples

Save a read-only Word document

1
2
3
4
5
6
7
var writer = new Writer();
writer.LoadText('<h1>Policy</h1><p>' + $Xml.Evaluate('PolicyText') + '</p>', 'html');

writer.Protection.StartEnforcingProtection('NoChanges', 'policy-owner');

$Files.AddBase64(writer.SaveToBase64('.docx'), 'Policy.docx',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document');