我已经在Magento 2应用程序中实现了TCPDF。我所做的是创建一个HTML文件,并将其加载到控制器中的TCPDF实例中。我在HTML标记中添加了所有的内联样式。但加载后,样式无法识别。不确定是什么,但其他样式,如背景色和字体大小,都很好。但当我试图在我的Div标签中添加空白或填充时,它仍然没有生效。你知道我如何加载HTML和css吗?下面是我的控制器中的HTML标记和tcpdf代码
HTML MARKUP
$pdf = new TCPDF(self::PAGE_ORIENTATION, self::PAGE_UNIT, [self::PAGE_SIZE_WIDTH, self::PAGE_SIZE_HEIGHT], true, 'UTF-8', false);
$pdf->SetCreator("Creator");
$pdf->SetAuthor('Author');
$pdf->SetTitle('Print');
$pdf->SetSubject('PDF');
$pdf->SetKeywords('pdf);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// remove default header/footer
$pdf->SetMargins(0, 0, 0, 0);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->setCellPaddings(0,0,0,0);
$pdf->setFooterMargin(0);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();
$html = <<<EOF
<div id="ecard-container">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="333" bgcolor="#6FFF66" height="270">
<div>
<img src="{$img}" width="220" height="270"/>
</div>
</td>
<td bgcolor="#990000" height="270">
<table>
<tr>
<td>
<div class="top-container">
<h1>The title</h1>
<div>Bought in your name from Gifts</div>
</div>
</td>
</tr>
<tr>
<td>Lorem Ipsum</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="bottom" bgcolor="#FFFFF0">
<div class="title" style="display: block;margin: 30px;">Thank you for saving a life today by providing medicine for a sick person in the developing world</div>
</td>
<td bgcolor="#CCCCCC" height="70">
<table>
<tr>
<td style="margin: 0.3in;padding: 0.3in;">
<div class="message"></div>
</td>
</tr>
<tr>
<td>
<span>Order number: 100051905</span>
</td>
</tr>
<tr>
<td>
<div>More info at www.goodgifts.org.</div>
</td>
</tr>
<tr>
<td>
<div>Tel: 020 7794 8000</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
EOF;
$pdf->writeHTML($html, true, false, true, false, '');
现在我尝试在HTML标记中添加内联样式,比如添加填充或边距,但没有生效。我也试着以隐姓埋名的方式观看,但没有效果。你知道怎么解决这个问题吗?
使用SetMargin代替
示例:
$pdf->SetMargins(10, 20, 10, true);
$pdf->AddPage();