简体   繁体   English

TCPDF:TD中文本和图像的垂直对齐

[英]TCPDF: Vertical alignment in a TD with text and image

I have been looking through various forums but have not found a way to solve my problem. 我一直在浏览各种论坛,但没有找到解决我的问题的方法。

I have a piece of HTML which I display in the view and render to PDF with TCPDF. 我在视图中显示了一段HTML,并使用TCPDF将其呈现为PDF。 The HTML looks fine but it does not seem to work in TCPDF. HTML看起来不错,但似乎在TCPDF中不起作用。

I have the following table cell that contains text (3a-2b) and next to it the image. 我有下面的表格单元格,其中包含文本(3a-2b),图像旁边。 The alignment should be like in the second image. 对齐方式应类似于第二张图片。

PDF: PDF: 表格单元格pdf Browser: 浏览器: 表格单元格html

but nothing seems to work. 但似乎没有任何效果。

I know I could use the entire text as an image but this is just an example. 我知道我可以将整个文本用作图像,但这只是一个例子。

Is there any other way? 还有其他办法吗?

将文本和图像放在单独的<td> ,并向包含文本的<td>施加6px的line-height可以解决问题。

Adding style="line-height:50%;" 添加样式=“ line-height:50%;” in image tag works for me. 图片标签中的图片对我有用。 Please give this a try. 请尝试一下。 In my case, I wanted to vertical align image in table cell. 就我而言,我想在表格单元格中垂直对齐图像。 You can add div in table cell and can add image or text inside it. 您可以在表单元格中添加div,也可以在其中添加图像或文本。 Below works for me. 下面为我​​工作。

<div align="center"><img src="images/logo_example.png" border="0" height="30" width="30" style="line-height:50%;"/></div>

TCPDF supports HTML and CSS very poorly, but there are some undocumented HTML and CSS attributes. TCPDF对HTML和CSS的支持非常差,但是有一些未记录的HTML和CSS属性。 Searching the sourcecode I found an "aling" attribute for the img tag supporting "middle". 搜索源代码后,我找到了支持“中间”的img标签的“ aling”属性。 So this could do what you want: <img src="..." align="middle"> 这样就可以完成您想要的操作: <img src="..." align="middle">

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

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