我想使用TCPDF从HTML生成PDF来制作一些标签。 (每张A4纸4张)。问题是我不会总是只有4 ...我可能有1到100.在每个标签中,a将有一个表,它将根据序列号从mysql数据库中获取一些细节。当我需要1或2或3个标签时,我需要其他空格为空。我不知道怎么做...从左到右打印div / table,然后在下一行打印。有人做过这样的事吗?
_____
|1 2|
|3 4|
答案 0 :(得分:0)
这就是我为了让它发挥作用所做的。所以,我需要A4纸上的4个标签,每个标签上都有2个桌子,一个顶部和一个底部,中间是空的。我在表中有很多表,但它可以在我需要的时候工作。我删除了与正在使用的mysql相关的任何内容。
<?php
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins(11, 14, 11);
$pdf->SetAutoPageBreak(true, 0);
$pdf->AddPage();
ob_start();
?><style>
tr.style10 {line-height: 10pt;}
tr.style12 {line-height: 12pt;}
tr.style20 {line-height: 20pt;}
tr.style30 {line-height: 30pt;}
tr.style110 {line-height: 110pt;}
tr.style360 {line-height: 360pt;}
</style>
?>
$x = $start+$quantity-1;
$r = fmod($quantity,2);
for($j=$start;$j<$x;$j+=2){
$i=$j+1;
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr width=\"100%\">
<td align=\"center\" width=\"45.5%\">
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style\" width=\"100%\">
<td align=\"center\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$j."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style30\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr class=\"style110\">
<td></td>
</tr>
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$j."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style20\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=\"9%\"></td>
<td align=\"center\" width=\"45.5%\">
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style\" width=\"100%\">
<td align=\"center\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$i."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style20\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr class=\"style110\">
<td></td>
</tr>
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$i."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style20\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br><br><br><br>";
}
if($r != 0){
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr width=\"100%\">
<td align=\"center\" width=\"45.5%\">
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style\" width=\"100%\">
<td align=\"center\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$x."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style20\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr class=\"style110\">
<td></td>
</tr>
<tr class=\"style2\">
<td>
<table align=\"center\" width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"2\">
<tr class=\"style20\">
<td width=\"100%\">
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style12\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
</table>
</td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"12\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\">".$x."</font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\"><font size=\"10\"></font></td>
</tr>
<tr class=\"style20\">
<td>
<table align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr class=\"style10\">
<td width=\"40%\"rowspan=\"2\"><img src=\"img/xz.png\" alt=\"\" width=\"50\"></td>
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"60%\" align=\"left\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
<tr class=\"style10\">
<td width=\"100%\" colspan=\"2\"><font size=\"8\"></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=\"9%\"></td>
<td align=\"center\" width=\"45.5%\">
</td>
</tr>
</table>";
}
$html = ob_get_clean();
$pdf->writeHTML($html);
$pdf->Output('your.pdf', 'I');