Karma
Karma

Reputation: 597

PHP Fatal error: Uncaught Error: Class "Mpdf\Mpdf" not found in C:\xampp\htdocs\server\pdf.php:5

PHP Fatal error: Uncaught Error: Class "Mpdf\Mpdf" not found in C:\xampp\htdocs\server\pdf.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\server\pdf.php on line 5

PHP 8.1.3, PHP Intelephense v1.8.2

compser.json

{
"require": {
    "mpdf/mpdf": "^6.1"
      }
}

composer.lock

{
    "name": "mpdf/mpdf",
    "version": "v6.1.2",
    "source": {
    "type": "git",
    "url": "https://github.com/mpdf/mpdf.git",
    "reference": "da078bc2669d3f98553ac41f920ead4c17c951ad"
        },

pdf.php

<?php

require_once __DIR__ . '/pdf/autoload.php';

$mpdf = new \Mpdf\Mpdf;
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();

What I am doing wrong? What I am not understanding?

Thank you for your help!

enter image description here

Upvotes: 1

Views: 23385

Answers (6)

Antonio Blanco Oliva
Antonio Blanco Oliva

Reputation: 11

I resolved this issue, removing mpdf folder and reinstall the last version using: composer require mpdf/mpdf

Upvotes: 1

bvr218
bvr218

Reputation: 1

laravel 10: use "new \mPDF();" instead "new \Mpdf\Mpdf;"

Upvotes: -1

Kelvin Mboto
Kelvin Mboto

Reputation: 370

If you are on a CodeIgniter/Laravel framework, just update your /App/Config/Constants.php COMPOSER_PATH variable to point to your right vendor folder URL.

defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . '../vendor/autoload.php');

I this case, I had moved my vendor folder out of the project folder.

This will make the class \Mpdf\Mpdf() available in all your Controllers and will reduce your require_once ROOTPATH. '/../vendor/autoload.php'; clauses all over.

But if you are using it once in your project it will be okay to

require_once __DIR__ . '/../vendor/autoload.php';

Make sure that you have installed Mpdf using composer

Upvotes: 0

Y. Joy Ch. Singha
Y. Joy Ch. Singha

Reputation: 3252

Laravel 8, got same error.

Just run the below in cmd then done.

composer require mpdf/mpdf

Upvotes: -2

Amit Dave
Amit Dave

Reputation: 626

In 6.1, there is no \Mpdf\Mpdf class, that is in v7+. So use here new mPDF();

require_once __DIR__ . '/pdf/autoload.php';

$mpdf = new mPDF();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();

Upvotes: 5

Omar Tammam
Omar Tammam

Reputation: 1304

require path need update to :

require_once __DIR__ . '/vendor/autoload.php';

Make sure that the library exists at vendor if not run composer update

Upvotes: 7

Related Questions