Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 16, 2021 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/56efcbfae80a8c8a93d11d9946aea2b6 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/56efcbfae80a8c8a93d11d9946aea2b6 to your computer and use it in GitHub Desktop.
Protect Word Documents using Python
import aspose.words as aw
# load document
doc = aw.Document("document1.docx")
# create document options
options = aw.saving.OoxmlSaveOptions(aw.SaveFormat.DOCX)
# set password
options.password = "password"
# save updated document
doc.save("document-password-protected.docx", options)
import aspose.words as aw
# load document
doc = aw.Document("document1.docx")
# apply document protection
doc.protect(aw.ProtectionType.READ_ONLY, "password")
# save updated document
doc.save("document-protected.docx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment