Dompdf Table 不适合
Dompdf Table not fit
我用 dompdf 制作 table 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元素缓冲它
print.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>
一些视图与页面完全相同,但为什么在中心 table 添加 table 一些不知从何而来,我的错误,我将我的代码转移到上面,没有人遗漏
pdf的结果是
...
这是网页浏览结果
来自 Dompdf github 页面:
Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
我最好的猜测是你的一些样式有 CSS3 Dompdf 不支持的属性,但你的浏览器支持,所以这就是你得到不同输出的原因。
看到您使用 bootstrap,我发现这些问题可能会有所帮助:
我用 dompdf 制作 table 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元素缓冲它
print.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>
一些视图与页面完全相同,但为什么在中心 table 添加 table 一些不知从何而来,我的错误,我将我的代码转移到上面,没有人遗漏
pdf的结果是
...
这是网页浏览结果
来自 Dompdf github 页面:
Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
我最好的猜测是你的一些样式有 CSS3 Dompdf 不支持的属性,但你的浏览器支持,所以这就是你得到不同输出的原因。
看到您使用 bootstrap,我发现这些问题可能会有所帮助: