我正在使用PHP、Smarty和TCPDF库来生成文档的PDF副本。该文档包含来自WIRIS编辑器的数学表达式图像以及文本内容。
我在正确定位表情图像旁边的文本时遇到了问题。
我尝试了CSS float
属性中的所有方法,但什么也没发生。我附上的屏幕截图正是我想要的这封邮件。
以下是打印问题及其选项的智能模板代码:
{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> {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}
这段代码可能包含一些错误,因为我在没有检查循环和括号完成的情况下随机粘贴了它,但这不是这里的问题。
这段代码中唯一重要的部分是打印问题文本和问题图像的行。
我研究了正确的解决方案,但没有得到想要的解决方案。有人能帮帮我吗。
发布于 2013-04-04 17:47:45
发现此代码可以正常工作
$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;"> <span style="color:black;">TC</span><span style="color:white;">PDF</span> </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);
发布于 2013-04-12 10:15:58
看起来所有不一致的信息都来自$qstn_ans.question_text
,所以上面的代码并没有什么问题。
我建议将该问题文本中的每个“声明”保存在单独的段落中。例如。
<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>
这应该会导致问题文本的每一行单独显示,而不会相互碰撞。
发布于 2013-05-06 23:51:18
我同意Nerdwood的观点,这看起来不像是一个Smarty问题;我认为这只是一个CSS问题。img
向下延伸到足以捕捉下一行文本的左边缘。你需要把文本压下来,这样它才能向左移动。您可以像clear: right;
一样将CSS属性放在img
上
我想这应该可以了。
https://stackoverflow.com/questions/15738866
复制相似问题