我想在pdf中使用mpdf,
在所有页面中设置所有页眉和页脚所以,我的代码看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title>Data Category</title>
<style type="text/css">
.page{
padding-top:2.5cm;
padding-right:1.5cm;
padding-left:1cm;
padding-bottom:5cm;
}
table{
border-spacing:0;
border-collapse: collapse;
width:100%;
page-break-inside:auto;
}
table td, table th{
border: 1px solid black;
}
</style>
</head>
<body>
<div class="page">
<table border="0">
<thead>
<tr>
<th>No</th>
<th>Tanggal</th>
<th>Jam</th>
<th>No struk</th>
<th>Nama</th>
<th>Quantity</th>
<th>Nama Item</th>
<th>Harga Jual</th>
<th>Sub total</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($data as $key => $value) {
?>
<tr>
<td><?= $no++ ?></td>
<td><?= $value['date_format'] ?></td>
<td><?= $value['jam'] ?></td>
<td><?= $value['struk_no'] ?></td>
<td><?= $value['nama_karyawan'] ?></td>
<td><?= $value['jumlah_jual'] ?></td>
<td><?= $value['nama_item'] ?></td>
<td><?= $value['harga_jual'] ?></td>
<td><?= $value['subtotal'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
我已经从这里阅读了他们的文档:mpdf docs。
但是,当我的表加载了多个页面时,该表会破坏标题:
$detail = Yii::$app->db->createCommand($this->getSqlReportDetail($parseStart, $parseEnd))->queryAll();
$html = $this->renderPartial('_report_detail', ['data' => $detail]);
$mpdf = new \mPDF('c', 'A4', '', '', 0, 0, 0, 0, 0, 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->SetHTMLHeader(''
. '<div style="text-align: center; font-weight: bold;">'
. '<h1>Hair Deeper Salon</h1><br>'
. '<hr>'
. '</div>'
);
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;">
<tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">{DATE j-m-Y}</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">My document</td>
</tr>
</table>
');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
答案 0 :(得分:0)
在设置页眉和页脚之前尝试使用此功能
$mpdf->setAutoTopMargin = 'stretch';
$mpdf->setAutoBottomMargin = 'stretch';