在使用 mpdf php 创建 pdf 文件之前验证内容

问题描述

我使用的是 kartik 的 yii2-mpdf。

我将 html 传递给 pdf 并渲染它,这是代码

          $pdf = new Pdf([
                //'debug' => true,//--> not supported in yii2-mpdf from kartik
                //'allow_output_buffering' => true,//--> not supported in yii2-mpdf from kartik
                // set to use core fonts only
                'mode' => Pdf::MODE_UTF8,// A4 paper format
                'format' => Pdf::FORMAT_A4,// portrait orientation
                'orientation' => Pdf::ORIENT_PORTRAIT,// stream to browser inline
                'destination' => Pdf::DEST_broWSER,'filename' => Yii::getAlias('@frontend/web/upload/pdf') . '/' . $fileName,// your html content input
                'content' => $content,// format content from your own css file if needed or use the
                // enhanced bootstrap css built by Krajee for mPDF formatting
                'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',// any css to be embedded if required
                'cssInline' => '.kv-heading-1{font-size:18px} .table-bordered > thead > tr > th{background:#3d2d3d;color: #FFF;}',// set mPDF properties on the fly
                'options' => ['title' => 'Report'],// call mPDF methods on the fly
                'methods' => [
                    //'SetHeader' => ['SALES ORDER'],'SetFooter' => ['{PAGENO}'],]
            ]);
         
            Yii::$app->response->format = Response::FORMAT_RAW;
            Yii::$app->response->headers->add('Content-Type','application/pdf');

            return $pdf->render();

但是很多次我收到损坏的 pdf 文件,那么有什么方法可以在将 Html 内容传递给 mpdf 之前对其进行验证?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)