user17699125
user17699125

Reputation:

I am Stuck with the error Class 'Mpdf\Mpdf' not found -php pdf creation

i've installed mpdf library with command composer require mpdf/mpdf.And it is installed in the location vendor/mpdf/src/Mpdf.php. And composer_autoload is true in config\autoload.php. with the below code, am getting the error Class 'Mpdf\Mpdf' not found. commenting use Mpdf\Mpdf; & uncommenting the lines i've commened below shows the error require_once(C:\xampp\htdocs\abcd\application\controllersvendor/mpdf/src/Mpdf.php): failed to open stream: No such file or directory.

My php version is 7.3.3.

How can i fix this? Can i get some help?

Controller

<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

use Mpdf\Mpdf;
//use \Mpdf\Mpdf;  //error- Class 'Mpdf\Mpdf' not found

<!--For the below 3, the error/warning is - `failed to open stream: No such file or directory` -->

//require_once __DIR__.'vendor/mpdf/src/Mpdf.php';  
//require_once __DIR__ . '/vendor/autoload.php';
//include_once('/mpdf/mpdf.php');

class Reports extends Layout_Controller
{
   public function downloadReport(){
        $fileName=$this->input->get('var');
        $mpdf=new Mpdf();
        $html=file_get_contents('reports/'.$fileName);
        $mpdf->WriteHTML($html);
        $mpdf->Output();
                
    }
}

composer.json

"require": {
        "php": ">=5.3.7",
        "mpdf/mpdf": "^8.0"
    }

Lines commented in this code are what i've tried .

Upvotes: 0

Views: 5482

Answers (1)

daniel
daniel

Reputation: 303

you still have to require_once 'vendor/autoload.php'; above your code.

This file is generated by composer and contains the information of autoloadable classes and the associated files.

Upvotes: 1

Related Questions