嗨我正在尝试使用html2pdf创建php文件的pdf,其中包含一个表,其中来自mysql数据库的数据被获取并通过使用while循环生成
但我想运行php文件
它说下面的错误
TCPDF错误:有些数据已经输出,无法发送PDF文件![在此输入图片说明] [1]
任何人都可以帮我解决问题
这是我的代码,
<?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;
}
?>
答案 0 :(得分:0)
在您输出这些标题之前,您已经获得了某种输出。有几件事要检查: