Reputation: 672
i am not able to generate pdf download,my code is as follows,can anyone tell me what is wrong with this code.
include 'tcpdf.php';
$pdf = new TCPDF();
$pdf->AddPage('P', 'A4');
$html = '<html>
<head></head>
<body><table border="1">
<tr><th>name</th>
<th>company</th></tr>
<tr>
<td>hello</td>
<td>xx technologies</td>
</tr>
</table>
</body>
</html>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output();
?>
Upvotes: 7
Views: 45894
Reputation: 391
Add this line $pdf->Output($downlaodname, 'D');
instead of $pdf->Output();
. It will force browser to download file.
Upvotes: 3
Reputation: 68446
I have modified your code and it works. [TESTED]
<?php
require_once('tcpdf_include.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();
$html = '<html>
<head></head>
<body><table border="1">
<tr><th>name</th>
<th>company</th></tr>
<tr>
<td>hello</td>
<td>xx technologies</td>
</tr>
</table>
</body>
</html>';
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('htmlout.pdf', 'I');
?>
OUTPUT:
Upvotes: 7
Reputation: 4911
If you want to make the file downloads, use PHP function header
before your $pdf->Output();
like this :
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
$pdf->Output(); # terminate your file with TCPDF output
See PHP function header on php.net
Upvotes: 4