php - 如何在 PDF 中正确定位图像旁边的文本?

标签 php css image smarty tcpdf

我正在使用 PHP、Smarty 和 TCPDF 库来生成文档的 PDF 副本。 该文档包含来自 WIRIS 编辑器的数学表达式图像以及文本内容。

我在正确定位表情图像旁边的文本时遇到问题。

我尝试了 CSS float 属性中的所有内容,但没有任何反应。我在这封邮件中附上了我想要的内容的屏幕截图。

这是打印问题及其选项的 smarty 模板代码:

{foreach from=$question_data item=qstn_ans key=key}
    <table border="0" width="100%" cellpadding="2" cellspacing="0">
        <tr>
            <td valign="top" >{if $qstn_ans.question_directions}{$qstn_ans.question_directions}<br /><b>Question {$que_seq_no} : </b>{/if}{$qstn_ans.question_text}</td>
        </tr>
        {if $qstn_ans.question_file}
        <tr>
            <td><img src="{$ques_thum_image_path}{$qstn_ans.question_id}_{$qstn_ans.question_file}" /></td>
        </tr>
        {/if}
        {if $qstn_ans.question_has_sub_ques==0}
            {if $qstn_ans.answer}
                {foreach from=$qstn_ans.answer item=ans key=ans_no}
                    <td valign="top" >
                        {if $ans.answer_is_right==1}{assign var='correct_ans' value=$ans_no+1}{/if}
                            <b>{$ans_no+1}.</b>&nbsp;&nbsp;{if $ans.answer_text!=''}{$ans.answer_text}{/if}
                            {if $ans.answer_file!=''}<img src="{$ans_thumb_img_path}{$ans.answer_id}_{$ans.answer_file}" />{/if}
                     </td>
                </tr>
                {/foreach}
        <tr>
            <td></td>
        </tr>
    </table>
{/foreach}

此代码片段可能包含一些错误,因为我在没有检查循环和括号是否完成的情况下随意粘贴了它,但这不是这里的问题。

此代码中唯一重要的部分是打印问题文本和问题图像(如果存在)的行。

我研究了正确的解决方案,但找不到想要的解决方案。谁能帮我吗。

Screenshot

最佳答案

发现这段代码工作正常

$html = <<<EOD
<h1><img src="http://www.google.com/logos/2013/wangari_maathai_73rd_birthday-1400005-hp.jpg" height="50px" width="150px"> Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1>
<i>This is the first example of TCPDF library.</i>
<p>This text <img src="http://www.google.com/logos/2013/wangari_maathai_73rd_birthday-1400005-hp.jpg" height="50px" width="150px"> <br>is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p>
<p>Please check the source code documentation and other examples for further information.</p>
<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p>
EOD;

// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

关于php - 如何在 PDF 中正确定位图像旁边的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15738866/

相关文章:

php - 从链接中获取值并将其用于标题属性

css - 隐藏标准的 AddThis 工具提示和图像

php - 我将如何在 php 中执行 mysql 时间戳?

php - 当新人在表单上注册时创建文件夹

css - 使文本 block 具有与页面页脚相同的垂直空间

java - 当正确回答时,在 GridView 中的图像上设置刻度线

javascript - 损坏的 Youtube 缩略图不会触发错误回调

php - MySQL SELECT MIN 对于所有时间,但仅在 BETWEEN 日期时返回

php - 为什么 geoip 会抛出异常?

html - 影响某些元素而不影响其他元素的媒体查询