这是我声明从表生成 pdf 的部分。我已经在 youtube 上观看了教程并按照所有步骤进行操作,但仍然出现错误。我是编程领域的新手,这是我的迷你项目之一。我得到的错误是:
注意:第 17162 行 C:\xampp\htdocs\tcpdff\tcpdf.php 中未定义偏移量:0
function fetch_data()
{
$output ='';
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM borang_permohonan";
$results = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($results))
{
$output .='
<tr>
<td>'.$row["fullname"].' </td>
<td>'.$row["ic_no"].'</td>
<td>'.$row["email"].' </td>
</tr>
';
}
return $output;
}
if(isset($_POST["create_pdf"]))
{
require_once('tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Export HTML Table data to pdf using TCPDF in PHP");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->SetFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false); //or true
$obj_pdf->SetAutoPAgeBreak(TRUE, 10);
$obj_pdf->SetFont('helvetica', '', 12);
$content = '';
$content .= '
<center><h2 >GSM 2019</h2></center>
<table align="center" border="1">
<thead>
<tr>
<th>fullname</th>
<th>ic no</th>
<th>email</th>
</tr>
</thead>
';
$content .= fetch_data();
$content .= '</table>';
$obj_pdf->writeHTML($content);
$obj_pdf->Output("sample.pdf", "I");
}
?>
Run Code Online (Sandbox Code Playgroud)
任何答案将不胜感激!谢谢你!
您需要AddPage在开始之前调用该方法WriteHtml
好地方可能是,就在之后SetFont
$obj_pdf->SetFont('helvetica', '', 12);
$obj_pdf->AddPage();
Run Code Online (Sandbox Code Playgroud)