Movatterモバイル変換


[0]ホーム

URL:


mPDF Manual – mPDF functions

SetProtection()

(mPDF ≥ 1.0)

SetProtection – Encrypts and sets the PDF document permissions

Description

voidSetProtection ( 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.

Parameters

$permissions

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 setfor$length.

Note: If 128-bit encryption is used (whether by specifying$length = 128 or 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.

Values (case-sensitive)

Anarray() including any, all or none of the following. The values included are those permissions allowed:

  • 'copy'
  • 'print'
  • 'modify'
  • 'annot-forms'
  • 'fill-forms'
  • 'extract'
  • 'assemble'
  • 'print-highres'
$user_password

Specify a password required for a user to open the PDF file.

BLANK or omitted - No password is required to open the PDF document.

$owner_password

Specify a password which will allow full access and permissions to the PDF file.

If omitted, or you pass innull, a random password is generated by mPDF

$length

Specify the bit-length used for encryption. Two values are possible,40 and128. The 4 latter$permissions (see above) require 128-bit encryption, and setting any of these willautomatically set$length as128, overriding any value specified.

Default:40 - use 40-bit encryption

Values

  • 40
  • 128

Changelog

VersionDescription
2.5CJK files can be encrypted
3.2Empty (blank array)$permissions array correctly handled.
5.3 Additional$permissions added, and$length parameter added enabling 128-bit encryption

Examples

Example #1

<?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');

Example #2

<?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');

[8]ページ先頭

©2009-2026 Movatter.jp