Pdf 功能* 从此函数获取数据后,此函数是从 ajax 调用的,它在此处调用另一个文件,我显示来自数据库的数据。该文件所有 css 部分都在样式标签中使用,因为它是 pdf 中的样式标签作为文本,如果所有 css 文件都包含在 css 文件夹中,则 pdf 不会以正确的格式创建
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();
}
发票打包数据.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>
如演示所述:
将跳过任何
<style>
标记(为此必须使用cssInline
属性)
如果您只有几个样式要添加到 pdf 中,则可以像这样传递它:
$pdf->content = $htmlContent;
$pdf->cssInline = '.class1 {color: red} .class2 {color:blue}';
但是如果你有很多样式,你也可以考虑使用正确的 css 将默认cssFile
更改为您想要的任何文件。(默认情况下,此属性@vendor/kartik-v/yii2-mpdf/assets/bootstrap.min.css