Download the library that I am using from a blog post on the ID Security Suite website :
<?php
function pdfEncrypt ($origFile, $password, $destFile){
require_once('FPDI_Protection.php');
$pdf =& new FPDI_Protection();
$pdf->FPDF('P', 'in');
$pagecount = $pdf->setSourceFile($origFile);
for ($loop = 1; $loop <= $pagecount; $loop++) {
$tplidx = $pdf->importPage($loop);
$pdf->addPage();
$pdf->useTemplate($tplidx);
}
$pdf->SetProtection(array(), $password);
$pdf->Output($destFile, 'F');
return $destFile;
}
$password = "testpassword";
$origFile = "sample.pdf";
$destFile ="sample_protected.pdf";
pdfEncrypt($origFile, $password, $destFile );
?>
source
share