我正在尝试使用 html2pdf 创建 php 文件的 pdf,该文件包含从 mysql 数据库中获取并使用 while 循环生成的 vich 数据表,但是当我尝试运行 php 文件时,它会显示以下错误
TCPDF ERROR: 一些数据已经输出,不能发送 PDF 文件
谁能帮我解决这个问题?这是我的代码:
<?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//error_reporting(0);
/*
Author : yaser kazi
Description : This File Contain Additions and Editing part for the Paxes
*/
if (!isset($_SESSION["username"])) {
header("location: unauthorize_access.html");
exit();
}
if (isset($_GET["cityprin"])) {
mysql_connect("localhost", "root", '') or die(mysql_error());
mysql_select_db('webapp') or die(mysql_error());
$get = mysql_query("SELECT code, `name` FROM city ORDER BY `name`") or die(mysql_error());
$ctr = 0;
ini_set("memory_limit", "50M");
ob_start();
?>
<style type="text/css" media="all">
<!--
body {
margin:0px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
span {
font-size:14px;
}
td {
width: 100mm;
max-width: 100mm;
height: 33mm;
max-height:33mm;
top:0mm;
}
table {
border-collapse:collapse;
}
-->
</style>
<?php
echo "<table border=\"1\" align=\"right\" style =\"width: 205mm;\">";
echo "<th>Srno</th>";
echo "<th>Code</th>";
echo "<th>Name</th>";
while ($city = mysql_fetch_array($get)) {
$ctr++;
echo "<td style=\"width: 100mm; max-width: 100mm; height:33mm; padding-left:1mm;\" valign=\"right\">".$ctr."</td>";
echo "<td style=\"width: 100mm; max-width: 100mm; height:33mm; padding-left:7mm;\" valign=\"right\">".$city['code']."</td>";
echo "<td style=\"width: 100mm; max-width: 100mm; height:33mm; padding-left:7mm;\" valign=\"right\">".$city['name']."</td>";
}
echo "</table>";
} // Submit Tag Close
?>
<?php
$content = ob_get_clean();
// conversion HTML => PDF
require_once('html2pdf/html2pdf.class.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'EN', false, 'ISO-8859-15', array("5mm", "13mm", "0mm", "0mm"));
$html2pdf->pdf->SetAuthor('CepheiSys');
$html2pdf->pdf->SetTitle('City_list');
// $html2pdf->pdf->SetSubject('HTML2PDF Wiki');
// $html2pdf->pdf->SetKeywords('HTML2PDF, TCPDF, example, wiki');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content);
$html2pdf->Output('City_list.pdf');
} catch (HTML2PDF_exception $e) {
echo $e;
}
?>