devraeph/laravel-pdf-protect

Password protect PDF in Laravel
79,791 6
Install
composer require devraeph/laravel-pdf-protect
Latest Version:3.3.0
PHP:^8.1|^8.2|^8.3|^8.4
License:MIT
Last Updated:Mar 23, 2026
Links: GitHub  ·  Packagist
Maintainer: devraeph

Laravel PDF Protect

Latest Version on Packagist Check & fix styling run-tests Total Downloads Issues

Simple wrapper package around MPDF's setProtection method that allows you to set password on PDF files.

Version Compatibilities

Laravel PDF Protect PHP Version Laravel 7.* Laravel 8.* Laravel 9.* Laravel 10.* Laravel 11.* Laravel 12.* Laravel 13.*
3.x >=8.1 - <= 8.4 :x: :x: :x: :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
2.x >=7.4 - <= 8.2 :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark: :x: :x: :x:
1.1.2 >=7.4 - <= 8.1 :white_check_mark: :white_check_mark: :white_check_mark: :x: :x: :x: :x:
1.0.0 >=7.4 - <= 8.0 :white_check_mark: :white_check_mark: :x: :x: :x: :x: :x:

Installation

You can install the package via composer:

composer require devraeph/laravel-pdf-protect

Usage

Version 3.x

In version 3.x the usage supports now multiple Storage support local, s3, ...

PDFPasswordProtect::setInputFile('pdf/LetterFormat.pdf','local|s3|...')
    ->setOutputFile('pdf/encrypted-123.pdf','local|s3|...')
    ->setPassword("1234")
    ->secure();

OLD Version 2.x

In version 2.x the usage is more common to use and simplified.

$inputFile = storage_path('pdf/LetterFormat.pdf');
$outputFile = storage_path('pdf/encrypted-123.pdf');

PDFPasswordProtect::setInputFile($inputFile)
    ->setOutputFile($outputFile)
    ->setPassword("1234")
    ->secure();

You can also add the optional method 'setOwnerPassword':

...

PDFPasswordProtect::setInputFile($inputFile)
    ...
    ->setOwnerPassword("1234")
    ->secure();

Alternative new options are: 'setMode' and 'setFormat'.

setFormat is default 'auto' and will now detect the document format. Before v2.x it was set to 'A4'.

PDFPasswordProtect::setInputFile($inputFile)
...
->setMode("en_GB") //You can set different language values. Default is utf-8
->setFormat("auto|A4|Letter") //You can set a Document format. Default is auto.
->secure();

Version 1.x

You can also use the old version from v1.x in v2.x, but it is deprecated and will no longer get any updates.

PdfPasswordProtect::encrypt(storage_path('pdf/document.pdf'),storage_path('pdf/'.'encrypted-documented.pdf'),'janedoe');

Encrypt method in detail

  • $inputFile and $outputFile has to be a path like storage_path("pdf/document.pdf")
PdfPasswordProtect::encrypt($inputFile,$outputFile,$password)

The final file will be located in storage/pdf as encrypted-document.pdf

Testing

composer test

Credits

Sponsor

ko-fi

License

The MIT License (MIT).

Related Packages

jamesking56/laravel-stagefront

Quickly add some password protection to a staging site.

8,006 1
codezero/laravel-stagefront

Quickly add some password protection to a staging site.

95,031 22
barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

27,935,098 2,755
elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3,080,940 355
mikemclin/laravel-wp-password

Laravel package that checks and creates WordPress password hashes

3,667,582 86