2010-03-30 148 views

回答

5

下載我從a blog post on the ID Security Suite site使用庫:我得到這個it..Try一個我張貼這裏的答案

<?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); 
?> 
+0

我們可以在沒有密碼的情況下在windows 8中查看這個加密文件。這在Windows 8中是失敗的。有沒有解決方案。謝謝 – user2092317 2015-05-08 19:49:47

0

我從來沒有找到一個直接的PHP解決這個問題。我最終使用pdftk並使用shell_exec()在生成/上傳PDF文件後調用二進制文件。

它接受一個語法如下:

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

@馬克。 – 2010-03-31 05:26:38

+0

bleee,windows軟件 – 2015-06-14 18:16:15