這就是我所做的工作。所以,我需要在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');
到目前爲止你做了什麼?請注意,Stackoverflow不是一個免費的編碼服務 – Trix
我完全忘了這個問題。我設法根據需要讓它工作,我很快就會發布答案。我知道這不是免費或付費的編碼服務,但會喜歡一個想法 – xlucian