【问题标题】:How to make pdf password protected in yii2 php如何在 yii2 php 中设置 pdf 密码保护
【发布时间】:2020-03-09 07:38:14
【问题描述】:

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

但它给了我这样的错误:Calling unknown method: kartik\mpdf\Pdf::setProtection();

我还尝试了以下将方法放在文件名之后的代码:

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

但它也给了我类似的错误:Call to a member function setProtection() on string.

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

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

【问题讨论】:

    标签: php yii2 pdf-generation password-protection mpdf


    【解决方案1】:

    试试

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2015-03-18
      相关资源
      最近更新 更多