Я пытаюсь преобразовать страницу HTML
в pdf, используя mpdf .
public function actionIndex()
{
$type = "";
$dataProvider = "";
$columns = "";
if(isset($_POST['cust_id']))
{
$type = "bill";
$content = $this->renderPartial('_bill', ['dataProvider' => $dataProvider]);
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
// A4 papr format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
//'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
//'cssInline' => '.kv-heading-1{font-size:14px}',
// set mPDF properties on the fly
'options' => ['title' => 'Bill'],
// call mPDF methods on the fly
'methods' => [
'SetHeader' => ['Generated On: ' . date("Y-m-d h:i:sa")],
'SetFooter' => ['{PAGENO}']
]
]);
$pdf->filename = "Bill.pdf";
try {
return $pdf->render();
} catch (MpdfException $e) {
} catch (CrossReferenceException $e) {
} catch (PdfTypeException $e) {
} catch (PdfParserException $e) {
} catch (InvalidConfigException $e) {
}
}
try {
return $this->render('index', [
'dataProvider' => $dataProvider,
'type' => $type
/*'searchModel' => $searchModel*/
]);
} catch (NotFoundHttpException $e) {
}
}
HTML Page
<?PHP
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->params['breadcrumbs'][] = $this->title;
?>
<!doctype HTML>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!--Css-->
<link rel="stylesheet" href="index.css">
<title>Electricity Bill</title>
</head>
<body>
<!--Main body-->
<div class="container">
<!--Header-->
<section class="row" style="border-bottom: tomato 2px solid; padding: 25px;">
<div class="col-3">
<img src="logo.jpg" alt="logo" class="size">
</div>
<div class="col-7 text">
<h5>Company</h5>
<h6>Web Site</h6>
<h6>Telephones:</h6>
<h6><u>Bill for electricity, Water and Allied Charges</u></h6>
</div>
</section>
<!--Ends-->
<!--Table Upper-->
<section class="row" style="margin-top: 10px;">
<!--Left Side-->
<div class="col-3 ">
<table class="table table-hover table-borderless ">
<tbody>
<tr>
<td>Consumer no</td>
<td>12345789</td>
</tr>
<tr>
<td>Address</td>
<td>Model Town</td>
</tr>
<tr>
<td>Consumer Name</td>
<td>Faisal</td>
</tr>
<tr>
<td>Meter No</td>
<td>43748</td>
</tr>
<tr>
<td>Meter Type</td>
<td>1/Phase</td>
</tr>
<tr>
<td>Previous Reading</td>
<td>178923</td>
</tr>
<tr>
<td>Current Reading</td>
<td>180199</td>
</tr>
<tr>
<td>Difference</td>
<td>1275</td>
</tr>
<tr>
<td>Average Units</td>
<td>0</td>
</tr>
<tr>
<td>Total Units</td>
<td>1275</td>
</tr>
</tbody>
</table>
</div>
<!--Ends-->
<!--Right Side-->
<div class="col-9">
<table class="table table-hover table-bordered ">
<thead>
<tr>
<th scope="col ">Billing Month</th>
<th scope="col ">M.R Date</th>
<th scope="col ">Issue Date</th>
<th scope="col ">Due Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>4 - 2020</td>
<td>27-APRIL-2020</td>
<td>05-MAY-2020</td>
<td>12-MAY-2020</td>
</tr>
</tbody>
</table>
<!--Second Table-->
<div class="row" style="margin-top: 10px;">
<div class="col-3">
<table class="table table-hover table-borderless">
<thead>
<tr>
<th scope="col" style="font-size: 16px;">Tariff</th>
<th scope="col">Member</th>
</tr>
<tr>
<th scope="col">Units</th>
<th scope="col">UnitRates</th>
</tr>
</thead>
<tbody>
<tr>
<td>1-100</td>
<td>14</td>
</tr>
<tr>
<td>1-100</td>
<td>14</td>
</tr>
<tr>
<td>101-300</td>
<td>17</td>
</tr>
<tr>
<td>101-300</td>
<td>17</td>
</tr>
<tr>
<td>301-700</td>
<td>20</td>
</tr>
<tr>
<td>301-700</td>
<td>20</td>
</tr>
<tr>
<td>above</td>
<td>21</td>
</tr>
<tr>
<td>above</td>
<td>21</td>
</tr>
</tbody>
</table>
</div>
<!--Bill History-->
<div class="col-9 ">
<table class="table table-hover table-bordered">
<thead>
<h4>Bill History</h4>
<tr>
<th scope="col">Month/Year</th>
<th scope="col">Units</th>
<th scope="col">Bill Amount</th>
<th scope="col">Payment</th>
</tr>
</thead>
</table>
<table class="table table-hover table-borderless">
<tbody>
<tr>
<td>3/2020</td>
<td>1,188</td>
<td>35,378</td>
<td>35,378</td>
</tr>
<tr>
<td>2/2020</td>
<td>1,405</td>
<td>35,378</td>
<td>35,378</td>
</tr>
<tr>
<td>1/2020</td>
<td>2,395</td>
<td>67,893</td>
<td>67,893</td>
</tr>
<tr>
<td>12/2019</td>
<td>3/2020</td>
<td>3/2020</td>
<td>3/2020</td>
</tr>
<tr>
<td>11/2019</td>
<td>877</td>
<td>33,034</td>
<td>33,034</td>
</tr>
<tr>
<td>10/2019</td>
<td>1,507</td>
<td>43,348</td>
<td>43,348</td>
</tr>
<tr>
<td>9/2019</td>
<td>1,812</td>
<td>51,798</td>
<td>51,798</td>
</tr>
<tr>
<td>8/2019</td>
<td>2,246</td>
<td>57,052</td>
<td>57,052</td>
</tr>
<tr>
<td>7/2019</td>
<td>2700</td>
<td>69,044</td>
<td>69,044</td>
</tr>
<tr>
<td>6/2019</td>
<td>2,383</td>
<td>60,375</td>
<td>60,375</td>
</tr>
<tr>
<td>5/2019</td>
<td>2,372</td>
<td>61,485</td>
<td>61,485</td>
</tr>
<tr>
<td>4/2019</td>
<td>1,728</td>
<td>48,804</td>
<td>48,804</td>
</tr>
<tr>
<td>3/2019</td>
<td>1,405</td>
<td>28,598</td>
<td>28,598</td>
</tr>
</tbody>
</table>
</div>
</div>
<!--End-->
</div>
<!--Horizontal Table 1-->
<table class="table table-hover table-bordered">
<thead>
<tr>
<th scope="col ">Energy Charge</th>
<th scope="col ">E-Arrears</th>
<th scope="col ">I-Tax</th>
<th scope="col ">GST</th>
<th scope="col ">E-Tax</th>
<th scope="col ">F-Tax</th>
<th scope="col ">R.G.S.T</th>
<th scope="col ">Total Amount</th>
<th scope="col ">Amt W Due date</th>
<th scope="col ">Amt A Due date</th>
</tr>
</thead>
<tbody>
<tr>
<td>26,096</td>
<td>3,433</td>
<td>0</td>
<td>5,020</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>34,549</td>
<td>34,549</td>
<td>34,845</td>
</tr>
</tbody>
</table>
<!--End-->
<!--Horizontal Table 2-->
<table class="table table-hover table-bordered ">
<thead>
<tr>
<th scope="col ">C-Duty</th>
<th scope="col ">Rd Maint</th>
<th scope="col ">Mosque</th>
<th scope="col ">Conserve</th>
<th scope="col ">Sewerage</th>
<th scope="col ">Misc</th>
<th scope="col ">Sanitation</th>
<th scope="col ">Tv fee</th>
<th scope="col ">Rent</th>
<th scope="col ">Rent Arrear</th>
<th scope="col ">Amt W Due date</th>
<th scope="col ">Amt A Due date</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>100</td>
<td>5</td>
<td>350</td>
<td>350</td>
<td>650</td>
<td>925</td>
<td>35</td>
<td>0</td>
<td>0</td>
<td>24,15</td>
<td>24,15</td>
</tr>
</tbody>
</table>
<!--end-->
<!--Horizontal Table 3-->
<table class="table table-hover table-bordered ">
<thead>
<tr>
<th scope="col ">F/MRC</th>
<th scope="col ">F/MRC Arrears</th>
<th scope="col ">Water Charges</th>
<th scope="col ">Water Arrears</th>
<th scope="col ">Total Amount</th>
<th scope="col ">Amt W.Due Date</th>
<th scope="col ">Amt A.Due Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0</td>
<td>1,060</td>
<td>0</td>
<td>1,060</td>
<td>1,060</td>
<td>1,070</td>
</tr>
</tbody>
</table>
<!--end-->
<!--Horizontal Table 4-->
<table class="table table-hover table-bordered ">
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Grand Total</td>
<td>38,024</td>
<td>39,339</td>
</tr>
</tbody>
</table>
<!--end-->
</section>
<!--Second Table-->
<!-- <section>
<div class="row ">
<img src="1.jpg" alt="" class="size-default">
</div>
</section>-->
<section>
<div class="row">
<div class=" col-2 cl">
<img src=" logo.jpg " alt=" logo " class=" size ">
</div>
<div class="col-8 text padding">
<h5>Company.</h5>
<h6><u>Bill for electricity, Water and Allied Charges</u></h6>
</div>
</div>
</section>
<section class="row">
<!--Horizontal Table 1-->
<table class=" table table-hover table-bordered ">
<thead>
<tr>
<th scope=" col ">Energy Charge</th>
<th scope=" col ">E-Arrears</th>
<th scope=" col ">I-Tax</th>
<th scope=" col ">GST</th>
<th scope=" col ">E-Tax</th>
<th scope=" col ">F-Tax</th>
<th scope=" col ">R.G.S.T</th>
<th scope=" col ">Total Amount</th>
<th scope=" col ">Amt W Due date</th>
<th scope=" col ">Amt A Due date</th>
</tr>
</thead>
<tbody>
<tr>
<td>26,096</td>
<td>3,433</td>
<td>0</td>
<td>5,020</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>34,549</td>
<td>34,549</td>
<td>34,845</td>
</tr>
</tbody>
</table>
<!--End-->
<!--Horizontal Table 2-->
<table class=" table table-hover table-bordered ">
<thead>
<tr>
<th scope=" col ">C-Duty</th>
<th scope=" col ">Rd Maint</th>
<th scope=" col ">Mosque</th>
<th scope=" col ">Conserve</th>
<th scope=" col ">Sewerage</th>
<th scope=" col ">Misc</th>
<th scope=" col ">Sanitation</th>
<th scope=" col ">Tv fee</th>
<th scope=" col ">Rent</th>
<th scope=" col ">Rent Arrear</th>
<th scope=" col ">Amt W Due date</th>
<th scope=" col ">Amt A Due date</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>100</td>
<td>5</td>
<td>350</td>
<td>350</td>
<td>650</td>
<td>925</td>
<td>35</td>
<td>0</td>
<td>0</td>
<td>24,15</td>
<td>24,15</td>
</tr>
</tbody>
</table>
<!--end-->
<!--Horizontal Table 3-->
<table class=" table table-hover table-bordered ">
<thead>
<tr>
<th scope=" col ">F/MRC</th>
<th scope=" col ">F/MRC Arrears</th>
<th scope=" col ">Water Charges</th>
<th scope=" col ">Water Arrears</th>
<th scope=" col ">Total Amount</th>
<th scope=" col ">Amt W.Due Date</th>
<th scope=" col ">Amt A.Due Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0</td>
<td>1,060</td>
<td>0</td>
<td>1,060</td>
<td>1,060</td>
<td>1,070</td>
</tr>
</tbody>
</table>
<!--end-->
<!--Horizontal Table 4-->
<table class=" table table-hover table-bordered ">
<tbody>
<tr>
<td>Consumer No</td>
<td></td>
<td>Billing Month</td>
<td></td>
<td>Grand Total</td>
<td>38,024</td>
<td>39,339</td>
</tr>
</tbody>
</table>
<!--end-->
</section>
Ошибка, которую я получаю: Undefined offset: -1
at if ($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] > 0 && !$this->mpdf->nestedtablejustfinished)
/* -- TABLES -- */
if ($this->mpdf->tableLevel) {
// If already something on the line
if ($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] > 0 && !$this->mpdf->nestedtablejustfinished) {
$this->mpdf->_saveCellTextBuffer("\n");
if (!isset($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'])) {
$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] = $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'];
} elseif ($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] < $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s']) {
$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] = $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'];
}
$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] = 0; // reset
}
Вот Fiddle