protectDocx

protectDocx

PREMIUM BASIC / ADVANCED

Password protects the contents of a Word document.

Description
public protectDocx (string $source, string $target, array $options)

This method allows to password protect a Word document. One may protect in read only mode or allow the final user to modify comments or form elements.

Notice that this method does not encrypt the contents of the Word document, only protects them from unauthorized modifications. This method is not secure and can be easily overriden by an experienced user.

You may find a detailed description of this package in the cryptophpdocx section of the API documentation.

Parameters

source

Path to the word document you want to protect.

target

Path to the resulting protected document.

options

The possible keys and values are (required options are shown with yellow background):

Key Type Description
password string The password should be a string of 15 or less characters. If you introduce a password with more than 15 characters it will be automatically truncated.
type string Available protection types:
  • readOnly (allows no editing. This is the default value).
  • comments (allows the edition of comments).
  • trackedChanges (allows editing with revision tracking).
  • forms (allows the edition of form fields).
overwrite bool True or false. If true (default value) overwrites the existing protection if it exists.
Return values

Void.

Code samples

Example #1

The resulting Word document looks like: