A library to add password protection to an existing PDF file

1.0.0 2020-04-24 11:08 UTC

This package is auto-updated.

Last update: 2021-09-24 14:39:57 UTC


This is a PHP wrapper library to add password encryption to an existing PDF file.

Driver 1 - FPDI

The first solution requires PHP only.

It uses FPDI to import all pages of the source PDF and add each page to a new file. Then, it outputs the file binary as a response.


  • PHP Only, no extra library needed


  • PDF version 1.5 or above is not supported, due to the limitation of the free PDF parser

Please be reminded to add the following packages to composer.json before you use this driver:

  "require": {
    "setasign/fpdi": "^2.0",
    "tecnickcom/tcpdf": "6.3.*"  

Driver 2 - QPDF

The second solution uses QPDF, which is a command line program. The solution simply calls shell_exec to execute QPDF and add the password.


  • Simple
  • Supports PDF version 1.5


  • Requires extra library installed on the system

For macOS, you may install QPDF with Homebrew:

brew install qpdf

For Ubuntu, you may install with apt:

apt-get install -y qpdf

If you are using other Linux distribution, please refer to the corresponding package repository.


The simplest usage is:

use INDZZ\PdfProtector\PdfProtector;

    ->protect('userPw', 'ownerPw')

See example folder for more details


This library is open-sourced under the MIT license.

Please also refer to the license of the