Как создать защищенный паролем pdf-файл

Я использую html2fpdf для создания PDF-документов. Теперь, когда я создал это, я хочу убедиться, что файл PDF защищен паролем. Как это можно сделать в PHP?

Загрузите библиотеку, которую я использую из сообщения в блоге на сайте ID Security Suite :

<?php function pdfEncrypt ($origFile, $password, $destFile){ require_once('FPDI_Protection.php'); $pdf =& new FPDI_Protection(); $pdf->FPDF('P', 'in'); //Calculate the number of pages from the original document. $pagecount = $pdf->setSourceFile($origFile); //Copy all pages from the old unprotected pdf in the new one. for ($loop = 1; $loop <= $pagecount; $loop++) { $tplidx = $pdf->importPage($loop); $pdf->addPage(); $pdf->useTemplate($tplidx); } //Protect the new pdf file, and allow no printing, copy, etc. and //leave only reading allowed. $pdf->SetProtection(array(), $password); $pdf->Output($destFile, 'F'); return $destFile; } //Password for the PDF file (I suggest using the email adress of the purchaser). $password = "testpassword"; //Name of the original file (unprotected). $origFile = "sample.pdf"; //Name of the destination file (password protected and printing rights removed). $destFile ="sample_protected.pdf"; //Encrypt the book and create the protected file. pdfEncrypt($origFile, $password, $destFile ); ?> 

Я никогда не мог найти прямое решение php для этой проблемы. Я закончил использование pdftk и использовал shell_exec() для вызова двоичного файла, когда файл PDF был сгенерирован / добавлен.

Он принимает такой синтаксис:

 pdftk 'inputfile.pdf' output 'outputfile.pdf' user_pw pass1234 owner_pw pass4321