如何在yii2 php中保护pdf密码

PHP的家伙

我想保护我的pdf密码。

我正在使用kartik \ mpdf \ Pdf扩展名生成pdf。

             $pdf = new Pdf([
                // set to use core fonts only
                'mode' => Pdf::MODE_CORE,
                // A4 paper format
                'format' => Pdf::FORMAT_A4,
                // portrait orientation
                'orientation' => Pdf::ORIENT_PORTRAIT,
                // stream to browser inline
                'destination' => Pdf::DEST_FILE,
                // your html content input
                'content' => $html,
                // any css to be embedded if required
                'cssFile' => '@api/web/css/notes.css',
                // set mPDF properties on the fly
                'options' => ['title' => $note['title']],
                // call mPDF methods on the fly
                'methods' => [
                    'SetHeader' => [''],
                    'SetFooter' => [''],
                ],
            ]);
            $pdf->content = $html;
            $file_name = "test" . rand(7, 100).pdf";
            $password = "122":
            $pdf->setProtection(array(),$password); 
            $pdf->filename = "uploads/" . $file_name;

            echo $pdf->render();

但这给了我类似的错误:调用未知方法:kartik \ mpdf \ Pdf :: setProtection();

我也尝试过以下将文件名后放置方法的代码:

$pdf->filename->setProtection(array(), $password);

但它也给我类似以下错误:在字符串上调用成员函数setProtection()。

我知道供应商的kartik库中提供了setProtection方法,但是我不确定如何使用它。

如果有人有想法请帮助我。

比兹利

尝试

$pdf->getApi()->setProtection();

方法getApi()是直接调用MPDF对象,这就是SetProtection()方法所在的位置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章