【发布时间】:2021-03-11 10:34:52
【问题描述】:
我用 dompdf 制作表格 pdf
喜欢这个
laporan.php
<table style="width:100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>NIS</th>
<th>NISN</th>
<th>Nama Siswa</th>
<th>Kelas Siswa</th>
<th colspan="3">Absensi</th>
<th colspan="5">Ekskul Wajib</th>
<th colspan="2">Ekskul Pilihan</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Ijin</td>
<td>Sakit</td>
<td>Absen</td>
<td>Pramuka SIT</td><td>Tahfidz</td><td>Melukis</td><td>Renang</td><td>Mentoring</td> <td>Pilihan</td>
<td>Nilai</td>
</tr>
<tr>
<td>1</td>
<td>0989</td>
<td>12345678</td>
<td>Dea</td>
<td>1A</td>
<td>4</td>
<td>5</td>
<td>2</td>
<td>A</td><td>B</td><td>C</td><td>D</td><td>A</td><td>Memanah</td><td>C</td></tr><tr>
<td>2</td>
<td>1234</td>
<td>90909090</td>
<td>Ardi</td>
<td>1A</td>
<td>1</td>
<td>0</td>
<td>3</td>
<td>C</td><td>D</td><td>B</td><td>E</td><td>A</td><td>Sepak Bola</td><td>A</td></tr><tr>
<td>3</td>
<td>2000</td>
<td>20202020</td>
<td>Azam</td>
<td>1A</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td></td><td></td><td></td><td></td><td></td><td>Memanah</td><td>A</td></tr>
</tbody>
</table>
然后用按钮导出并用css元素缓冲
打印.php
<?php
$value='laporan.php';
ob_start();
require 'dompdf/autoload.inc.php';
$abc= include $value;
$css= include 'css.php';
use Dompdf\Dompdf;
$dompdf= new Dompdf();
$dompdf->loadHtml(ob_get_clean());
$dompdf->setPaper('A4','landscape');
$dompdf->render();
$dompdf->stream($value,array("Attachment"=>0));
?>
和css.php
<style type="text/css" media="all">
<!-- BOOTSTRAP STYLES-->
<?php include 'assets/css/bootstrap.css' ?>
<!-- FONTAWESOME STYLES-->
<?php include 'assets/css/font-awesome.css'?>
<!-- PAGE LEVEL STYLES-->
<?php include 'assets/css/error.css'?>
<!-- GOOGLE FONTS-->
<?php include 'assets/css/basic.css'?>
<?php include 'assets/css/custom.css'?>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
.table-no-border tr td th{
border : none;
}
td {
height: 50px;
vertical-align: middle;
text-align: center;
}
</style>
某些视图与页面完全相同,但是为什么在表格的中心添加了一些不知从何而来的表格,我的错误,我将我的代码转移到上面并且没有人丢失
pdf的结果是
这是来自网络视图的结果
【问题讨论】: