devraeph / laravel-pdf-protect
Password protect PDF in Laravel
Installs: 52 561
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/contracts: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- mpdf/mpdf: ^8.1.3
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.13
- nunomaduro/collision: ^7.8
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^6.0|^7.0|^8.0|^8.8
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-11-21 09:39:13 UTC
README
Simple wrapper package around MPDF's setProtection
method that allows you to set password on PDF files.
Version Compatibilities
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
- Owen Jubilant (creator of the original package) - PDF Password Protect
- DevRaeph (refactored classes to comply with PSR-4)
Sponsor
License
The MIT License (MIT).