我在 php 中有我的代码,我打算从我的数据库中制作一个 pdf。我尝试阅读并找到用于创建 pdf 的 tcpdf。我下载它并尝试它的一些代码。创建pdf时真的需要$html吗?或者我下面带有回声的代码可以吗?每当我运行时总是出现错误:
注意:未定义的偏移量:16906 行 C:\xampp\htdocs\TopHealth\tcpdf\tcpdf.php 中的 0
注意:未定义的偏移量:17277 行 C:\xampp\htdocs\TopHealth\tcpdf\tcpdf.php 中的 0
TCPDF ERROR: 一些数据已经输出,无法发送 PDF 文件..
<?PHP
require_once('tcpdf/config/tcpdf_config.php');
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inventory", $con);
$result = mysql_query("SELECT * FROM critical");
echo "<center>";
echo "<table class='table1'>
<tr class='tablelist'>
<th>Code</th>
<th>Item Description</th>
<th>Beginning Balance</th>
<th>Reg. Quantity</th>
<th>Quantity Received</th>
<th>Consumed</th>
<th>Stock Level</th>
<th>Critical?</th>
</tr>";
echo "</center>";
while($row = mysql_fetch_array($result))
{
echo "<tr class='tablelist'>";
echo "<td>" . $row['CODE'] . "</td>";
echo "<td>" . $row['Item_Description'] . "</td>";
echo "<td>" . $row['Beginning_Balance'] . "</td>";
echo "<td>" . $row['Reg_Quantity'] . "</td>";
echo "<td>" . $row['Quantity_Received'] . "</td>";
echo "<td>" . $row['Consumed'] . "</td>";
echo "<td>" . $row['Stock_Level'] . "</td>";
echo "<td>" . $row['rate'] . "</td>";
echo "</tr>";
}
echo "</table>";
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('name.pdf', 'I');
mysql_close($con);
?>
谢谢