TCPDF 和使用添加的 CSS 的问题
我正在尝试将 TCPDF 与我自己的类一起使用来发布 HTML 中已经存在的一些内容,但我无法让 CSS 发挥作用(无论如何也不完全)。
我知道它是一个 PDF 库,不能处理所有 CSS,但我所做的只是一些(非常)基本的格式设置。
我可能正在做一些非常愚蠢的事情,但我一生都看不到它。
无论如何,我正在创建一个带有样式属性的变量,如下所示:
$html = <<<EOF
<style>
table.phonelist {
border:1px solid black;
}
td {
border:1px solid black;
}
td.header1 {
background-color: #cccccc;
border-bottom:1px solid black;
font-weight: bold;
text-align: center;
font-size: 12pt;
}
td.header2 {
font-weight:bold;
text-align:center;
font-size:12pt;
}
td.lname {
font-weight:bold;
}
td.ext {
text-align:center;
}
</style>
EOF;
然后我在该字符串的末尾添加一些 html 并将其写入页面,HTML 呈现良好,并且某些样式,例如 header1样式是较大的字体大小并居中,但背景颜色似乎没有任何作用。
任何人都可以提供任何帮助,那就太好了,如果它只是指出我的愚蠢那么仍然有效:-)
干杯。
I'm trying to use TCPDF with my own classes to publish some content that is already existing in HTML and I can't get the CSS to play ball (not completely anyway).
I know it's a pDF library and doesn't handle all CSS, but all I'm doing is some (very) basic formatting.
I'm probably doing something really stupid, but for the life of me I can't see it.
Anyway, I'm creating a variable with the style attributes in it like this:
$html = <<<EOF
<style>
table.phonelist {
border:1px solid black;
}
td {
border:1px solid black;
}
td.header1 {
background-color: #cccccc;
border-bottom:1px solid black;
font-weight: bold;
text-align: center;
font-size: 12pt;
}
td.header2 {
font-weight:bold;
text-align:center;
font-size:12pt;
}
td.lname {
font-weight:bold;
}
td.ext {
text-align:center;
}
</style>
EOF;
Then I add some html onto the end of that string and write it out to the page, the HTML renders fine and SOME of the styles, for instance the header1 style is the larger font size and centered, but the background-color doesn't seem to do antything.
Anyone can be of any help it would be great, if it is just pointing out my stupidity then would still work :-)
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用过 TCPDF 和 colspan 工作得很好,但我认为(不幸的是)在将 HTML 转换为 TCPDF 时您始终必须使用内联样式,否则结果可能是不可预测的。
我知道这很无聊并且会导致大量重复,但这种方式 colspan 和 style 非常适合我。
I've used TCPDF and colspan works perfectly, but i think that (unfortunately) you always have to use inline styles when converting HTML to TCPDF otherwise results might be unpredictable.
I know it's boring and lends to a lot of repetition, but that way colspan and style work perfectly for me.
TCPDF 中的 CSS 几乎不存在。要获得任何类型的可用 CSS,您可能需要切换到 dompdf https://github.com/dompdf/dompdf< /a> 可以读取外部样式表、内联样式标签等
CSS in TCPDF is mostly non-existent. To get any kind of useable CSS you might want to switch to dompdf https://github.com/dompdf/dompdf which can read external stylesheets, inline style tags etc