简体   繁体   English

使用DOMPDF转换器在PDF中无法正确呈现简单表

[英]Simple tables not rendering correctly in PDF with DOMPDF converter

I am using DOMPDF to convert HTML to PDF. 我正在使用DOMPDF将HTML转换为PDF。 Two simple tables that are next to one another on the browser don't render on PDF the same, ie the second table appears in a new line. 浏览器上彼此相邻的两个简单表不会在PDF上呈现相同的外观,即第二个表出现在新行中。 Here is the HTML: 这是HTML:

<html>
<head>
    <style>
        .simple_table { 
            width: 200px;
            float: left; 
        }
    </style>
</head>
<body>
        <div class="simple_table">
             <table >
                <tr><td>table1 </td></tr>
                <tr><td>table1 </td></tr>
            </table>
        </div>
        <div class="simple_table">
            <table >
                <tr><td>table2</td></tr>
                <tr><td>table2</td></tr>
            </table>
        </div>
</body>
</html> 

And the PHP to invoke DOMPDF converter: 和PHP来调用DOMPDF转换器:

$dompdf = new DOMPDF();
$html = file_get_contents("http://linkToAboveHTML");
$dompdf->load_html($html);
$dompdf->set_paper('A4','potrait');
$dompdf->render();
$dompdf->stream("dompdf.pdf");

Float support is still an "experimental" feature of dompdf as of v0.6.1, and it's disabled by default. 从v0.6.1开始,浮动支持仍然是dompdf的“实验性”功能,默认情况下处于禁用状态。 You can enable float support by setting the DOMPDF_ENABLE_CSS_FLOAT configuration constant to true. 您可以通过将DOMPDF_ENABLE_CSS_FLOAT配置常量设置为true来启用浮动支持。

Starting in 0.6.1 you can also change settings in the instantiated object by calling the set_option method, eg $dompdf->set_option('enable_css_float',true) . 从0.6.1开始,您还可以通过调用set_option方法来更改实例化对象中的设置,例如$dompdf->set_option('enable_css_float',true)

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

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