(mPDF ≥ 1.0)
SetProtection – Encrypts and sets the PDF document permissions
void SetProtection ( array $permissions [, string $user_password [, string $owner_password [, integer $length ]]])
Encrypts and sets the PDF document permissions for the PDF file, together with user and owner passwords.
Note: A default mPDF document is not encrypted, and grants full permissions to the end-user e.g. copying, printing, modifying.
This parameter is an array which specifies the permissions granted to the end-user.
A blank array should be passed to deny all permissions to the user. The latter 4 permissions were added in mPDF ≥5.3
Using any of these last 4 permissions require 128-bit encryption and will force this mode, regardless of any value set for $length.
Note: If 128-bit encryption is used (whether by specifying
$length = 128or by using any of the 4 latter permissions), the use of
'print'will only allow low-resolution printing from the document; you must specify
'print-highres'to allow full resolution printing.
array()including any, all or none of the following. The values included are those permissions allowed:
Specify a password required for a user to open the PDF file.
BLANK or omitted - No password is required to open the PDF document.
Specify a password which will allow full access and permissions to the PDF file.
If omitted, or you pass in
null, a random password is generated by mPDF
Specify the bit-length used for encryption. Two values are possible,
128. The 4 latter $permissions (see above) require 128-bit encryption, and setting any of these will automatically set $length as
128, overriding any value specified.
40- use 40-bit encryption
|2.5||CJK files can be encrypted|
|3.2||Empty (blank array) $permissions array correctly handled.|
|5.3||Additional $permissions added, and $length parameter added enabling 128-bit encryption|
<?php $mpdf = new \Mpdf\Mpdf(); // Encrypt the file and grant no permissions to the user to copy, print etc. // The user will be able to open the file as no password is specified // Owner cannot access full rights because no owner_password was set $mpdf->SetProtection(array()); $mpdf->WriteHTML('Hello World'); $mpdf->Output('filename.pdf');
<?php // Encrypt the file and grant no permissions to the user // The user will need to use "UserPassword" to open the file // Owner has full rights using the password "MyPassword" $mpdf->SetProtection(array(), 'UserPassword', 'MyPassword'); // Encrypt the file and grant permissions to the user to copy and print // No password is required to open the document // Owner has full rights using the password "MyPassword" $mpdf->SetProtection(array('copy','print'), '', 'MyPassword');