【问题标题】:Design error in pdf export - Dompdf/tcpdfpdf 导出中的设计错误 - Dompdf/tcpdf
【发布时间】:2016-04-11 14:52:20
【问题描述】:

我正在开发一个旅行门户网站,它对于制作 pdf 机票预订至关重要。我使用了 Dompdf 和 tcPdf。但是从两个库导出的 pdf 都存在设计错误。

这是我的实际 HTML 设计

这是生成的 PDF

我的 HTML 设计代码

<table class="col-xs-12 other-table" style="text-align:left">
  <tr>
    <td>TICKET ID</td>
    <td>&nbsp;</td>
    <td><span>LD324865</span></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>PACKAGE NAME</td>
    <td>&nbsp;</td>
    <td><span>LAKSHADWEEP SUMMER PACKAGE</span></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>DATE OF BOOKING</td>
    <td>&nbsp;</td>
    <td><span>28 May 2016</span></td>
    <td>DATE OF JOURNEY</td>
    <td>&nbsp;</td>
    <td><span>31 May 2016</span></td>
  </tr>
</table>
<style>
.grey-color{
color:#666; 
}
.total-cost{font-size:18px}
.address{
font-size:11px;
}
.heading{
border-bottom:1px #CCCCCC solid;
}
.package-name{
font-size:15px;
margin:15px 0px;
}
.package-name span{
    padding:10px !important;background:#EAEAEA;
}
.table{font-size:14px}
.other-table td{padding: 12px 0px !important;font-size:12px}
.other-table span{background:#EAEAEA;padding:16px !important;}
.uppercase{text-transform:uppercase !important;}

</style>

生成PDF的PHP代码

<?php 
require_once 'dompdf/autoload.inc.php';


// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$html = file_get_contents('holiday.html');
$dompdf->loadHtml($html);


// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();
?>

如何获得正确的 pdf 设计? 我不想要任何付费图书馆。有没有其他 PHP PDF 库可以做到这一点?

【问题讨论】:

    标签: php pdf tcpdf dompdf


    【解决方案1】:

    dompdf 目前(包括 0.7.0 版)对内联元素的填充没有很好的支持。您可以切换到块元素(P 或 DIV)并看到更好的结果。

    在 0.7.0 中,您还可以通过将 span 显示样式设置为 inline-block 来修复样式。

    【讨论】:

    • 我尝试使用 div、span 和 p 进行布局。现在还不错!
    猜你喜欢
    • 2015-01-03
    • 1970-01-01
    • 2021-10-01
    • 2011-06-22
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    相关资源
    最近更新 更多