PHPackages                             indzz/pdfprotect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. indzz/pdfprotect

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

indzz/pdfprotect
================

A library to add password protection to an existing PDF file

1.0.0(6y ago)0217MITPHPPHP ^7.1CI failing

Since Apr 24Pushed 6y agoCompare

[ Source](https://github.com/indzz/pdfprotect)[ Packagist](https://packagist.org/packages/indzz/pdfprotect)[ RSS](/packages/indzz-pdfprotect/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

PDF Protection
==============

[](#pdf-protection)

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

Driver 1 - FPDI
---------------

[](#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.

Advantage:

- PHP Only, no extra library needed

Disadvantage:

- 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
---------------

[](#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.

Advantage:

- Simple
- Supports PDF version 1.5

Disadvantage:

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

Example
-------

[](#example)

The simplest usage is:

```
