Just follow the steps below to create PDF from view of CodeIgniter (Without composer)
Step 1: First download DOMPDF without composer(Eg. dompdf_1-0-2.zip) from here. Now paste it into Libraries directory under Application
Step 2: Now create a file "Pdf.php" into Libraries folder with the following code.
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf extends Dompdf {
public function __construct() {
parent::__construct();
}
}
?>
Step 3: Now create a method in the required Controller to make PDF from the view as shown.
function GeneratePdf(){
// Load pdf library
$this->load->library('pdf');$this->load->view('myView'); $html = $this->output->get_output(); $this->pdf->loadHtml($html); $this->pdf->setPaper('A4', 'landscape'); $this->pdf->render(); // Output the generated PDF (1 = download and 0 = preview) $this->pdf->stream("my.pdf", array("Attachment"=> 0)); }
Now your view will be created as PDF.
Happy Coding.....
ConversionConversion EmoticonEmoticon