Yii2 Kartik mPDF - How to set footer only on the last page of the document

60 Views Asked by At

For my document generation I am using Kartik's mPDF plugin. I need the footer only on the last page of the document. I tried couple of way for the same. But unable to achieve it. Now the footer is available in every page. I need to keep the header for all pages and only need to show the footer on last page. Sharing my code for the reference.

Controller

 public function actionPrint($id)
{
    $model = $this->findModel($id);
    if ($model->is_printed == "0") {
        $model->is_printed = '1';
        $model->printed_by = Yii::$app->user->id;
        $model->save(false);
    }
    $modelQtn = QuotationDetails::find()->where(['qd_q_id' => $model->po_qtn_id, 'qd_is_selected' => '1'])->all();
    Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
    $pdf = new Pdf([
        'mode' => Pdf::MODE_CORE,  // leaner size using standard fonts
        'destination' => Pdf::DEST_BROWSER,
        'orientation' => Pdf::ORIENT_PORTRAIT,
        'format' => [210, 250],
        'content' => $this->renderPartial('print', [
            'model' => $model,
            'quotations' => $modelQtn,
            // 'page' => ['{PAGENO} of {nb}'],
        ]),
        'filename' => $model->po_no . 'filename.pdf',
        'cssFile' => [
            '@vendor/../backend/assets/css/custom-style.css',
            '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',

        ],
        // any css to be embedded if required
        'cssInline' => '
        @media print {
            body {
            }
            .pagebreak {
                clear: both;
                page-break-after: always;
            }
       
        }
        
        ',
        'marginHeader' => 15,
        'marginTop' => 55,
        'marginBottom' => 55,
        'marginFooter' => 30,
        'options' => [
            // any mpdf options you wish to set
            'title' => 'Purchase Order',
            'defaultheaderline' => 0,
        ],
        'defaultFont' => 'Montserrat',
        'methods' => [
            'SetTitle' => $model->po_no . 'filename.pdf',
            'SetSubject' => 'Al Nassar Trading and Contracting Co',
            'SetHeader' => $this->renderPartial('header', [
                'model' => $model,
                'quotations' => $modelQtn,
                'pageNo' => ['{PAGENO} of {nb}'],
            ]),
            'SetAuthor' => 'Company Name',
            'SetCreator' => 'Company Name',
            'SetKeywords' => 'Company Name',
            'SetWatermarkText' => 'DRAFT',
            'SetWatermarkImage' => Yii::$app->homeUrl . 'assets/images/logo/company-logo.png',
            'SetFooter' => $this->renderPartial('footer', [
                'model' => $model,
                'quotations' => $modelQtn,
                'pageNo' => ['{PAGENO} of {nb}'],
            ]),
        ]
    ]);
    return $pdf->render();
}. 

Can anyone help me to find what mistake I made here or can any one suggest me any documentation or links where I can find a solution.

0

There are 0 best solutions below