to generate pdf download using tcpdf

前端 未结 3 506
醉话见心
醉话见心 2020-12-11 05:28

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         


        
相关标签:
3条回答
  • 2020-12-11 06:00

    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:

    enter image description here

    0 讨论(0)
  • 2020-12-11 06:00

    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

    0 讨论(0)
  • 2020-12-11 06:00

    Add this line $pdf->Output($downlaodname, 'D'); instead of $pdf->Output();. It will force browser to download file.

    0 讨论(0)
提交回复
热议问题