简体   繁体   English

Dompdf 表格不适合

[英]Dompdf Table not fit

im make table pdf with dompdf我用dompdf制作表pdf

like this像这样

laporan.php 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>

then export it with button and buffer it with css element然后使用按钮将其导出并使用 css 元素对其进行缓冲

print.php 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));
?>

and css.php和 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>

some view is exactly same with the page, but why on center the table add table some from nowhere, where my mistake, i transfer my code above and no one missing某些视图与页面完全相同,但是为什么在表格的中心添加一些表格,这是我的错误,我将我的代码转移到上面并且没有人丢失

the result of pdf is pdf 的结果是

... ... 此图像来自 dompdf 结果

this is from web view result这是来自 web 查看结果

网页结果

From the Dompdf github page:来自Dompdf github页面:

Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules

My best guess here is that some of your styling has CSS3 properties that Dompdf does not support, but your browser does, so that is why you get different outputs.我最好的猜测是,您的某些样式具有 Dompdf 不支持的 CSS3 属性,但您的浏览器支持,这就是您获得不同输出的原因。

Seeing that you use bootstrap, I found these issues that might help:看到您使用引导程序,我发现这些问题可能会有所帮助:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM