首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未发现的错误:未找到类FPDI_Protection,尽管它存在于FPDI_Protection.php文件中

未发现的错误:未找到类FPDI_Protection,尽管它存在于FPDI_Protection.php文件中
EN

Stack Overflow用户
提问于 2022-07-20 18:05:34
回答 1查看 41关注 0票数 0

我试图用PHP脚本密码保护PDF文档。因此,我下载并在脚本中包含了FPDI_Protection.php文件,其中包含了FPDI_Protection类。

但是,当我试图执行脚本时,它说当类FPDI_Protection在提到的文件中明显存在时,它是找不到的。我还在堆栈溢出上检查了其他答案,其中说要使用seta符号\但是在包含类的文件中没有声明这样的名称空间。

此外,我也不使用composer作为依赖项。

我的密码就像

代码语言:javascript
复制
<?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文件在脚本当前目录的资产文件夹下。我已经从这里下载了脚本。

如果该链接不起作用,请参阅整篇文章这里

试着用各种可能的方法来修复,但没有一种有效。你能指出我正在做的错误吗?

EN

回答 1

Stack Overflow用户

发布于 2022-07-21 07:35:55

您不应该使用一个脚本的博客帖子,这是近14年前!只需使用官方和最新版本的FPDI保护类,这是可用的这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73056306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档