<!DOCTYPE html>
<body>
<?php
function fetch_data(){
$output = '';
$conn = mysqli_connect("localhost", "root", "", "something");
$ID = $_COOKIE['ID'];
$sql_0 = "SELECT users.name, leave_form.type_of_leave, leave_form.application_date,leave_form.leave_days,
leave_form.starting_date,leave_form.end_date,leave_form.reporting_date ,leave_form.Approval FROM users,leave_form WHERE
users.ID=leave_form.ID && leave_form.Approval='Denied' ";
$result = mysqli_query($conn, $sql_0);
while($row = mysqli_fetch_array($result)){
$output .='
<form method="POST" action="../auth/processes.php">
<tr><td><input type="text" value= '.$row["name"].' readonly class="form-control"/></td>
<td><input type="text" value="'.$row["type_of_leave"].'" readonly class="form-control"/></td>
<td><input type="timestamp" value="'.$row["application_date"]. '" readonly class="form-control"/></td>
<td><input type="number" value="'.$row["leave_days"].'" readonly class="form-control"/></td>
<td><input type="date" value="'.$row["starting_date"].'" readonly class="form-control"/></td>
<td><input type="date" value="'.$row["end_date"]. '" readonly class="form-control"/></td>
<td><input type="text" value="'.$row["Approval"]. '" readonly class="form-control"/></td>
<td><a href="../auth/authenticate.php"><img src="../assets/images/send.png" alt="post" height="40px"/></a></td></tr></form>
</form>';
}
return $output;
}
if(isset($_POST["generate_pdf"])){
require_once('../tcpdf/tcpdf.php');
$obj_pdf = new TCPDF ('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf -> SetCreator(PDF_CREATOR);
$obj_pdf -> SetTitle("My first pdf");
$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_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf -> SetDefaultMonospacedFont('helvetica');
$obj_pdf -> SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf -> SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
$obj_pdf -> setPrintHeader(false);
$obj_pdf -> setPrintFooter(false);
$obj_pdf -> setAutoPageBreak(TRUE, 10);
$obj_pdf -> SetFont('helvetica', '', 11);
$obj_pdf -> AddPage();
$content = '';
$content .= '
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th width = "14.28%" >Name</th>
<th width = "14.28%" >Type of Leave</th>
<th width = "14.28%" >Application Date</th>
<th width = "14.28%" >Leave Days</th>
<th width = "14.28%" >Starting Date</th>
<th width = "14.28%" >End Date</th>
<th width = "14.28%" >Approval</th>
</tr>
';
$content .= fetch_data();
$content .= '</table>';
$obj_pdf -> writeHTML($content);
$obj_pdf -> Output('file.pdf', 'I');
}
?>
<div class="col-md-12" align="right">
<form method="post">
<input type="submit" name="generate_pdf" value="Generate PDF"/>
</form>
<table class="table table-striped table-bordered troom">
<thead>
<tr>
<th>Applicant Name</th>
<th>Type of Leave</th>
<th>Application Date</th>
<th>Days Applied For</th>
<th>Starting Date</th>
<th>End Date</th>
<th>Approval</th>
</tr>
</thead>
<tbody>
<?php
echo fetch_data();
?>
</tbody>
</table>
</body>
</html>
上述代码在尝试将我的html表格转换为pdf时会产生以下错误:任何帮助都会有所帮助
注意:未定义的索引:第16916行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的行
警告:array_push()期望参数1为数组,在第16918行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中给出null
注意:未定义的索引:第16498行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的thead
警告:第18807行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的非法字符串偏移'url'
注意:未定义的索引:第19478行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的trid
警告:在第19478行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中为foreach()提供的参数无效
注意:未定义的索引:19507行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的trid
警告:count():参数必须是在19507行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中实现Countable的数组或对象
注意:未定义的索引:第19510行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的trid
警告:在第19510行的C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中为foreach()提供的参数无效
注意:第19720行C:\ xampp \ htdocs \ novel \ tcpdf \ tcpdf.php中的未定义索引:old_cell_padding
TCPDF错误:某些数据已经输出,无法发送PDF文件
答案 0 :(得分:0)
我看到的一个主要问题是,即使您想要生成PDF,也要将HTML输出到页面。这是导致此错误的原因:
TCPDF错误:某些数据已经输出,无法发送PDF文件
您可以通过转到TCPDF示例并在文件的开头或结尾插入文本或HTML元素来测试它。