Simple wrapper package around MPDF's setProtection
method that allows you to set password on PDF files.
Laravel PDF Protect | PHP Version | Laravel 6.* | Laravel 7.* | Laravel 8.* | Laravel 9.* | Laravel 10.* | Laravel 11.* |
---|---|---|---|---|---|---|---|
3.x |
>=8.1 - <= 8.3 |
❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
2.x |
>=7.4 - <= 8.2 |
❌ | ✅ | ✅ | ✅ | ✅ | ❌ |
1.1.2 |
>=7.4 - <= 8.1 |
❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
1.0.0 |
>=7.4 - <= 8.0 |
✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
You can install the package via composer:
composer require devraeph/laravel-pdf-protect
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();
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();
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
composer test
- Owen Jubilant (creator of the original package) - PDF Password Protect
- DevRaeph (refactored classes to comply with PSR-4)
The MIT License (MIT).