HTML Rendering with TCPDF(PHP)

自作多情 提交于 2019-11-29 08:09:33

Are you using tags? tcpdf's HTML engine gives the tag precedence over any CSS, or other size-adjusting tags. If you remove any extraneous tags from the HTML and use straight CSS, things should render as expected. Or, if you aren't using CSS, you should. Just because a browser displays it correctly doesn't mean it will look the same on other formats. The browser has likely performed some magic of its own to fill in the gaps in your CSS specifications.


UPDATE

Here's an example of specifying CSS declarations with your HTML when using tcpdf. Note how all the styling is applied using the CSS declarations inside the <style> tag outside the actualy HTML body.

<?php

$html = <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<style>
  h1 {
    color: navy;
    font-family: times;
    font-size: 24pt;
    text-decoration: underline;
  }
  p {
    color: red;
    font-family: helvetica;
    font-size: 12pt;
  }
</style>
<body>
<h1>Example of <i>HTML + CSS</i></h1>
<p>Example of 12pt styled paragraph.</p>
</body>
EOF;

$pdf->writeHTML($html, true, false, true, false, '');

?>
Jeremy Harris

TCPDF recognizes basic CSS such as font-size, font-color, and font-family.

For a little more information, check out TCPDF not render all CSS properties

The best solution that worked for me was to replace 'px' to 'pt' in html code:

$tidy = str_replace ('px', 'pt', $tidy);

Before on the left side and after replacing on the right:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!