本文介绍了如何创建受密码保护的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用html2fpdf创建PDF文档.现在,一旦我创建了该文件,便要确保PDF文件受密码保护.如何在PHP中完成此操作?
I'm using html2fpdf for creating PDF documents. Now once I have created that, I want to make sure that the PDF file is password protected. How can this be done in PHP?
推荐答案从 ID安全套件网站上的博客帖子:
<?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 ); ?>更多推荐
如何创建受密码保护的pdf文件
发布评论