Online Snippets Library

TCPDF Integration In Laravel

TCPDF is a PHP class for generating pdf documents.TCPDF is free and open source library. .we will use following step for TCPDF integration with Laravel.

  1. To Download TCPDF Click Here.

  2. create library folder inside app directory.

  3. Unzip the above download inside app/library/tcpdf.

  4. Create a new file inside app/library/Pdf.php

  5. <?php
    require_once __DIR__.'/tcpdf/tcpdf.php';
    
    class Pdf extends TCPDF
    {
    }
    /* End of file Pdf.php */
    /* Location: ./app/library/Pdf.php */
    
  6. Open composer.json file and add below lines to the classmap section.

  7. "app/library", "app/library/pdf.php",
  8. Now we will create route for tcpdf integration.

  9. Route: Route::resource('tcpdfDemo','TcpdfController');
  10. Create Controller file inside app/controllers/TcpdfController.php.
  11. <?php
    class TcpdfController extends BaseController {
        public function index () {
        $pdf = new TCPDF();
        $pdf->SetPrintHeader(false);
        $pdf->SetPrintFooter(false);
        $pdf->AddPage();
        $pdf->Text(90, 140, 'TCPDF Demo');
        $filename = storage_path() . '/tcpdfDemo.pdf';
        $pdf->output($filename, 'F');
        return Response::download($filename);
    }
    }
    ?>
    
  12. Run "composer dump-autoload".

remove-index.php-from-url-in-codeigniter