gpt4 book ai didi

php - 如何创建受密码保护的 pdf 文件

转载 作者:可可西里 更新时间:2023-11-01 00:53:20 31 4
gpt4 key购买 nike

我正在使用 html2fpdf 创建 PDF 文档。现在,一旦我创建了它,我想确保 PDF 文件受密码保护。这如何在 PHP 中完成?

最佳答案

a blog post on the ID Security Suite site下载我正在使用的库:

<?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 - 如何创建受密码保护的 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2545804/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com