Skip to content

Instantly share code, notes, and snippets.

@deselbi
Last active June 6, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deselbi/dd7184dcaed8891f1eb0b5cc7379ce98 to your computer and use it in GitHub Desktop.
Save deselbi/dd7184dcaed8891f1eb0b5cc7379ce98 to your computer and use it in GitHub Desktop.
Encrypt PDF created with laravel DOMPDF
use \PDF;
use Symfony\Component\Process\InputStream;
use Symfony\Component\Process\Process;
...
$pdf = PDF::loadHTML($html);
$stream = $pdf->stream();
$input = new InputStream();
$command = 'pdftk - output - user_pw '.$password;
$process = new Process($command);
$process->setInput($input);
$process->start();
$input->write($stream->content());
$input->close();
$process->wait();
$encriptedPdfContent = $process->getOutput();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment