我试图用PHP脚本密码保护PDF文档。因此,我下载并在脚本中包含了FPDI_Protection.php文件,其中包含了FPDI_Protection类。
但是,当我试图执行脚本时,它说当类FPDI_Protection在提到的文件中明显存在时,它是找不到的。我还在堆栈溢出上检查了其他答案,其中说要使用seta符号\但是在包含类的文件中没有声明这样的名称空间。
此外,我也不使用composer作为依赖项。
我的密码就像
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
function pdfEncrypt ($origFile, $password, $destFile){
require_once("assets/fpdi/FPDI_Protection.php");
$pdf =& new FPDI_Protection();
// set the format of the destinaton file
$pdf->FPDF("P", "in", array('8.27','11.69'));
//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);
}
//password for the pdf file
$password = "test";
//name of the original file
$origFile = "cv.pdf";
//name of the destination file
$destFile ="cv_test.pdf";
//encrypt the book and create the protected file
pdfEncrypt($origFile, $password, $destFile );
?>我的FPDI_Protection.php文件在脚本当前目录的资产文件夹下。我已经从这里下载了脚本。
如果该链接不起作用,请参阅整篇文章这里。
试着用各种可能的方法来修复,但没有一种有效。你能指出我正在做的错误吗?
发布于 2022-07-21 07:35:55
您不应该使用一个脚本的博客帖子,这是近14年前!只需使用官方和最新版本的FPDI保护类,这是可用的这里。
https://stackoverflow.com/questions/73056306
复制相似问题