PDF document security
A PDF document can be encrypted to protect its contents from unauthorized
access or modifications.
PD4ML can be forced to perform PDF document encryption by pd4ml.setPermissions()
PD4ML supports the following PDF security features.
Protecting PDF document with a password.
pd4ml.setPermissions("my_secret_password", 0xffffffff, true);
The above example only defines document password, and does not impact document access permissions (all permissions bits are set to TRUE in 0xffffffff).
If a document reader types the correct password, he is alowed to print, annotate etc.
pd4ml.setPermissions("empty", 0xffffffff ^ PD4Constants.AllowPrint, true);
The example does not defines any password ("empty" is a special keyword there, means no password protection to enable).
But it explicitly disables document printing with 0xffffffff ^ PD4Constants.AllowPrint permissions mask.
Need to disable more permissions?
Just cascade them:
0xffffffff ^ PD4Constants.AllowPrint ^
PD4Constants.AllowContentExtraction ^ PD4Constants.AllowFillingForms.
pd4ml.setPermissions("my_secret_password", PD4Constants.AllowFillingForms | PD4Constants.AllowPrint, true);
This API call combines the password protection and the permission control.
In the case it does not disable permissions, but enables them. All other
permissions are implicitly disabled.
The third setPermissions() parameter controls if the
encryption must be strong (128bit) or not (40bit). Nowadays there
is no good reason to use the weak encryption - any saved CPU time by the
encryption is not going to be noticeable - so the recommended value for the
parameter is true.