dompdf - 文本换行不起作用

时间:2014-06-07 08:57:49

标签: php html pdf dompdf

我有动态html内容来创建pdf。所以我正在使用Dompdf

这是两个快照,有助于理解我想要的是什么。

我的HTML在浏览器中显示这个SNAP

enter image description here

结果PDF

enter image description here

现在您可以看到我的html文本和pdf文本。 pdf文本应与html相同。

我不知道为什么会这样。并且不用担心文字字体。但在我的html文本中,文本看起来有两行,但在pdf中,它出现在一行中。我还使用了word-wrap:break-word; css,但我认为Dompdf不支持。

这是我的代码:

<?php
require_once '/path/to/dompdf/dompdf_config.inc.php';

$dir          = __DIR__ . '/../public';
$pdfDirectory = $dir . '/testing-pdf';
$pdfFilename  = $pdfDirectory  . '/output.pdf';

$buffer = <<<HTML
<style>@page {
    margin: 36 50;
} </style>
<div style='width:400px;height:300px;background:#C0C0C0;position:relative;'>
    <div style='width:200px;height:100px;position:absolute;top:100px; left:90px;'>
        <p style='text-align:center;padding:0px;margin:2px 0;font-size:24pt;font-family:arial; word-wrap:break-word; border:1px solid black;'>
            Abcd abc ab a
        </p>
    </div>
</div>
HTML;

$dompdf = new DOMPDF();
$dompdf->load_html($buffer);
$dompdf->set_paper(array(0, 0, 400, 300), "portrait");
$dompdf->render();

file_put_contents($pdfFilename, $dompdf->output());

1 个答案:

答案 0 :(得分:1)

好的..所以最后我得到了一些能让它发挥作用的东西。实际上我只是在寻找包装文本,但我忘了字体也是一个问题。我在Arial中使用html content字体,可以使用浏览器。但我发现dompdf本身并未包含Arial字体。每当我创建pdf时,它都会更改字体Arial to Times new RomanTimes new RomanArial更薄。这就是为什么第二行采用第二行文字。

相关问题