如何在yii2 php中保护pdf密码

问题描述 投票:1回答:1

我想保护我的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()。

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

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

php yii2 pdf-generation password-protection mpdf
1个回答
0
投票

尝试

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

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

© www.soinside.com 2019 - 2024. All rights reserved.