Skip to content

Commit

Permalink
protect pdfs with mulitple pages --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen-oj committed Mar 8, 2022
1 parent d27cfa1 commit 488a498
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/PDFPasswordProtect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ class PdfPasswordProtect
public function encrypt($inputFile, $outputFile, $password, $ownerPassword = null)
{
$mpdf = new \Mpdf\Mpdf();

$pagecount = $mpdf->setSourceFile($inputFile);
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);

$pageCount = $mpdf->setSourceFile($inputFile);

for ($page = 1; $page <= $pageCount; $page++) {
$tplId = $mpdf->importPage($page);
$wh = $mpdf->getTemplateSize($tplId);
$mpdf->AddPage($wh['width'] > $wh['height'] ? 'L' : 'P');
$mpdf->UseTemplate($tplId);
}

//set owner password to user password if null
$ownerPassword = is_null($ownerPassword) ? $password : $ownerPassword;
Expand Down

0 comments on commit 488a498

Please sign in to comment.