php - How to set css at time of PDF creation in yii2? -


pdf fuction* function call ajax after getting data function it's call anothe file here display data coming data base.that file css part in style tag using style tag prind in pdf text , if css file include in css folder pdf not create in proper format

public function actioninvoicespacking(){      $pdf = yii::$app->pdf;     $modelshipment = shipment::find()->orderby('ship_id desc')->one();     if(count($modelshipment) == 0) {        $shipid= 1;     } else      {      $shipid= $modelshipment->ship_id;     }    $htmlcontent = file_get_contents('http://localhost/shepherdlogistics_v1.0/backend/views/shipment/invoicespackingdata.php');    $pdf->content = $htmlcontent;    return $pdf->render();   } 

invoicespackingdata.php

<!doctype html> <html lang="en">  <head>     <title>invoice</title>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1">     <link rel="stylesheet" href="css/bootstrap.fontawesome.min.css">     <link rel="stylesheet" href="css/stylepdf.css">     <script src="js/jquery.min.js"></script>     <script src="js/bootstrap.min.js"></script>     <style type="text/css">     body {         font-size: 18px;         font-family: cambria;     }      .nopadd {         padding: 0px;     }     </style> </head>  <body>     <div class="container">         <br>         <br>         <div class="">             <div class="col-lg-2 nopadd">                 <img src="logopdf.png" alt="logo" width="100%">             </div>             <div class="col-lg-10">                 <h1 style="font-size: 55px;font-weight: bold; padding: 23px 0px;">                 shepherd logistics co. w.l.l.</h1>             </div>         </div> </div> </div> 

as demo states:

any <style> tag skipped (you must use cssinline property this)

if have few styles add pdf, can pass this:

$pdf->content = $htmlcontent; $pdf->cssinline = '.class1 {color: red} .class2 {color:blue}'; 

but if have alot of styles, can consider change default cssfile file want correct css. (by default, property @vendor/kartik-v/yii2-mpdf/assets/bootstrap.min.css


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -