kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
161 stars 150 forks source link

Debug toolbar markup appended to PDF #93

Closed skills-up closed 5 years ago

skills-up commented 5 years ago

Hi,

Any PDF that I generate using this option appends the debug toolbar CSS mark-up after the main content.

#yii-debug-toolbar-logo { position: fixed; right: 31px; bottom: 4px; } .yii-debug-toolbar { font: 11px
Verdana, Arial, sans-serif; text-align: left; width: 96px; transition: width .3s ease; z-index: 1000000; } .yiidebug-toolbar_active { width: 100%; } .yii-debug-toolbar_position_top { margin: 0 0 20px 0; width: 100%;
} .yii-debug-toolbar_position_bottom { position: fixed; right: 0; bottom: 0; margin: 0; } .yii-debugtoolbar__bar { position: relative; padding: 0; font: 11px Verdana, Arial, sans-serif; text-align: left; overflow:
hidden; box-sizing: content-box; background: rgb(255, 255, 255); background: -moz-linear-gradient(top,
rgb(255, 255, 255) 0%, rgb(247, 247, 247) 100%); /* FF3.6-15 */ background: -webkit-linear-gradient(top,
rgb(255, 255, 255) 0%, rgb(247, 247, 247) 100%); /* Chrome10-25,Safari5.1-6 */ background: lineargradient(to bottom, rgb(255, 255, 255) 0%, rgb(247, 247, 247) 100%);
...

My pdf controller function is as below:

    public function actionPdf($id) {
        $model = $this->findModel($id);

        $content = $this->renderAjax('_pdf', [
            'model' => $model,
        ]);

        $pdf = new \kartik\mpdf\Pdf([
            'mode' => \kartik\mpdf\Pdf::MODE_BLANK,
            'format' => \kartik\mpdf\Pdf::FORMAT_A4,
            'orientation' => \kartik\mpdf\Pdf::ORIENT_PORTRAIT,
            'destination' => \kartik\mpdf\Pdf::DEST_BROWSER,
            'content' => $content,
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            'cssInline' => '.kv-heading-1{font-size:18px}',
            'options' => ['title' => \Yii::$app->name],
            'methods' => [
                'SetHeader' => [\Yii::$app->name],
                'SetFooter' => ['{PAGENO}'],
            ]
        ]);

        return $pdf->render();
    }
kartik-v commented 5 years ago

You are supposed to normally remove yii2 debug component out from yii2 app config in your production environment. Not sure why you need that in your production. Anyway,, irrespective of above note that the mpdf library will convert solely the HTML markup generated by you to PDF You need to isolate the html content you pass to mpdf without rendering other scripts or css like yii2-debug. (E.g. rightly using renderPartial instead of renderAjax)