首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在PDF中正确定位图像旁边的文本?

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

Stack Overflow用户
提问于 2013-04-01 14:42:45
回答 5查看 2.7K关注 0票数 12

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

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

我尝试了CSS float属性中的所有方法,但什么也没发生。我附上的屏幕截图正是我想要的这封邮件。

以下是打印问题及其选项的智能模板代码:

代码语言:javascript
复制
{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

EN

回答 5

Stack Overflow用户

发布于 2013-04-04 17:47:45

发现此代码可以正常工作

代码语言:javascript
复制
$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);
票数 1
EN

Stack Overflow用户

发布于 2013-04-12 10:15:58

看起来所有不一致的信息都来自$qstn_ans.question_text,所以上面的代码并没有什么问题。

我建议将该问题文本中的每个“声明”保存在单独的段落中。例如。

代码语言:javascript
复制
<p>Statement I: The variance of first n even natural numbers is <img src="?" /></p>
<p>Statement II: The sum of first n natural numbers is <img src="?" /></p>
<p>and the sum of squares of first n natural numbers is <img src="?" /></p>

这应该会导致问题文本的每一行单独显示,而不会相互碰撞。

票数 1
EN

Stack Overflow用户

发布于 2013-05-06 23:51:18

我同意Nerdwood的观点,这看起来不像是一个Smarty问题;我认为这只是一个CSS问题。img向下延伸到足以捕捉下一行文本的左边缘。你需要把文本压下来,这样它才能向左移动。您可以像clear: right;一样将CSS属性放在img

我想这应该可以了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15738866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档