K
K
KevinSmash2019-04-26 23:38:24
css
KevinSmash, 2019-04-26 23:38:24

Why don't css styles work when transferring a file to PDF?

Goodnight. In the view, there is a php file that consists of html code and in some places php code is inserted with data from the model, like this:

Счет на оплату № <?= $id = time();?> от <?= $date = date('d.m.Y');?>

A separate file was created for it in the style.css view and tried to connect it through the command:
<link type="text/css" rel="stylesheet" href="style.css" media="all" />

This file is converted to pdf and displayed on the server, but is displayed without applying css properties. The question is why does not work, just in case the controller code:
public function actionSend($id)
    {
        $model = $this->findModel($id);
        $pdf = new Pdf([
            'mode' => Pdf::MODE_UTF8, // leaner size using standard fonts
            'content' => $this->renderPartial('send.php', [
                'model' => $this->findModel($id),
            ]),
            'options' => [
                'title' => 'Privacy Policy - Krajee.com',
                'subject' => 'Generating PDF files via yii2-mpdf extension has never been easy'
            ],
            'methods' => [
                'SetHeader' => ['Generated By: ARIANA WORLDWIDE||Generated On: ' . date("r")],
                'SetFooter' => ['|Page {PAGENO}|'],
            ]

        ]);
        echo $this->render('send', ['model' => $model]);
        if ($id) {
            $content = $pdf->content;
            $filename = $pdf->filename;

            /*$mpdf = $pdf->getApi();
            $mpdf->WriteHtml($content);*/
            $path = $pdf->Output($content, Yii::getAlias('@backend') . '/uploads/pdf/' . $filename . '.pdf', \Mpdf\Output\Destination::FILE);

            $sendemail = Yii::$app->mailer->compose()
                ->attach(Yii::getAlias('@backend') . '/uploads/pdf/' . $filename . '.pdf')
                ->setFrom('[email protected]')
                ->setTo('[email protected]')
                ->setSubject('Счёт Alisa Market')
                ->send();
            if ($sendemail) {
                unlink(Yii::getAlias('@backend') . '/uploads/pdf/' . $filename . '.pdf');
                return $this->render('send');
            }
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arseny, 2019-04-26
@KevinSmash

CSS has a media query that is responsible for print renderings, but it's related to print preparation, not generated files. Those. these styles will work (if they are correctly spelled out) when trying to transfer the page (I emphasize) to print. How this happens, you can see by pressing Ctrl + P (or find in the settings \ context of the browser menu sending to print).
At the output, for example, in Google Chrome, you can choose to convert to PDF. It is then that the styles that were previously displayed in the print panel will be applied.
Specifically, in your case, the request under the conditions of the module may look like "yii2 mpdf css". Where in the results (and there are many) you can find " how to attach " the CSS file to the module.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question