I am using TCPDF to generate the pdf file.
<form method='post'>
<input type='submit' name='create_pdf' class='gs-btn-3' value='Create PDF'/>
</form>
<?php
if (isset($_POST["create_pdf"]))
{
require_once("myPDF/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('Thisi is Serena first PDF example');
$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(PDF_FONT_MONOSPACED);
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$obj_pdf->SetPrintHeader(false);
$obj_pdf->SetPrintFooter(false); //true
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('dejavusans', '', 14);
$obj_pdf->AddPage();
$content = '
<h3 align="center"> Export HTML Table data to PDF using TCPDF in PHP</h3>
<table border="1" cellspacing="6" cellpadding="4">
<tr>
<th width="25%" align="center">Company Name</th>
<th width="25%">Contact</th>
<th width="10%">Address</th>
<th width="10%">Phone</th>
<th width="10%">Modify by</th>
<th width="10%">Modify on</th>
<th width="10%">EDIT</th>
</tr>
if(isset($this->culist) && is_array($this->culist) && sizeOf($this->culist) > 0) {
foreach($this->culist as $key=>$value) {
<tr>
<td style="width: 25%;">
<?php echo $value->companyname; ?>
</td>
<td style="width: 25%;">
<?php echo $value->firstname; ?>
</td>
<td style="width: 10%;">
<?php echo $value->address; ?>
</td>
<td style="width: 10%;">
<?php echo $value->phone; ?>
</td>
<td style="width: 10%;">
<?php echo $value->modified_by; ?>
</td>
<td style="width: 10%;">
<?php echo $value->modified_on; ?>
</td>
</tr>
}
</table>
';
$obj_pdf->WriteHTML($content, true, false, true, false, '');
ob_end_clean();
$obj_pdf->Output('sample.pdf', 'I');
}
?>
There are two errors,
First is the "TCPDF ERROR: Some data has already been output, can't send PDF file". I tried "ob_end_clean();" before "$obj_pdf->Output('sample.pdf', 'I');", it shows so many unreadable code.
Second is that the generated table is not from the scripts which showed above, rather the table comes from the the view.
Anyone who can help me? Thanks in advance.