I have a problem with Kartik/mPDF that is not generate correctly the pdf. I use it in my model class and call the method from the action in a Controller.
Here are the code:
Model
public function CreatePdf(){
$content = "<h1>helo</h1>";
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content
]);
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', 'application/pdf');
return $pdf->render();
}
Controller:
public function actionCreate(){
$model = new MElettrico();
$model_Utente = new AzioniUtente();
$searchModel = new CRUDSearch();
if ($model->load($this->request->post())){
/* if($this->request->post('QE_QB') == 1)
$model->QE_QB = 'QE';
else
$model->QE_QB = 'QB';
*/
// $model->StringaToDate(Yii::$app->request->post('Tempi_Consegna'));
$model_Utente -> username = Yii::$app->user->identity->username;
$model_Utente -> Lettura_QRCode_At = date('Y-m-d H:i:s');
$model_Utente -> Stato_Oggetti = $model->Stato;
$model_Utente -> Azione = 'CREATE';
$model_Utente -> save();
$qrCode = (new QrCode('http://192.168.0.47:8080/index.php?r=site%2Fobject&Codice_Interno='.$model->Codice_Interno))
->setSize(75)
->setMargin(5)
->useForegroundColor(51, 153, 255);
$qrCode->writeFile('C:/Users/carlo.lazzari/Desktop/prova/QRCodes/' .$model->Nome_Sullo_Schema. '.jpg');
$model->CreatePdf();
$model->save();
$query = (new Query())->from('m_elettrico')
->where(['ID_Commessa' => Yii::$app->session->get('Commessa')])
->orderBy('Stazione_Appartenenza');
$dataProvider = new ActiveDataProvider([
'query' => $query
]);
$dataProvider = $searchModel->search($this->request->queryParams);
return $this->render('magazzinoElettrico', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
return $this->render('create', [
'model' => $model,
]);
}
can someone help me?
Thanks in advance!