5

I'm trying to use MPDF but when loading it I get the following error, does anyone know why?https://github.com/mpdf/mpdf

enter image description here

My Code

 <?php 

  require_once APPPATH.'/third_party/mpdf/src/Mpdf.php';

  $mpdf = new mPDF('c','A4');
  $mpdf->writeHTML('<div>HELLO WORLD</div>'); 
  $mpf->Output('new.pdf','I');

  ?>
CristianOx21
  • 217
  • 1
  • 4
  • 16
  • How did you acquire mpdf? From Github or composer? – Dan Oct 12 '17 at 21:34
  • Github, in the usage guide it says require_once __DIR__. '/vendor/autoload.php'; but I can not find that route (start trying it today, because I want to implement it in my project) – CristianOx21 Oct 12 '17 at 21:40
  • I would suggest you follow the installation instruction found on the readme: https://github.com/mpdf/mpdf otherwise you will have to manage the dependencies and drive yourself crazy – Dan Oct 12 '17 at 21:40
  • I'm supposed to create a JSON file using this ... I'd like to run it from Composer ... but I do not understand what I'm supposed to write inside ... could you help me with the JSON please? I use windows 7 https://packagist.org/packages/mpdf/mpdf#v7.0.0-RC3 – CristianOx21 Oct 12 '17 at 22:46
  • Follow instructions on composer documentation website https://getcomposer.org/doc/00-intro.md#installation-windows – Finwe Oct 13 '17 at 07:58

3 Answers3

3

There are two points. 1: go to your php.ini file and uncomment the ;extension=gd remove semicolon from start. 2: run the command composer require mpdf/mpdf v8.1.2 -W.

This works fine for me

Atiq krl1
  • 57
  • 8
1

Most likely there will be a compatibility issue with the package (mpdf) version and the language(PHP) version After several attempts, the compatibility between Jazm and language(PHP) was discovered as follows.

  • mPDF >=7.0 is supported on PHP ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0
  • PHP 7.3 is supported since mPDF v7.1.7
  • PHP 7.4 is supported since mPDF v8.0.4
  • PHP 8.0 is supported since mPDF v8.0.10
  • PHP 8.1 is supported as of mPDF v8.0.13

If you have trouble installing the package, use the following command

composer require mpdf/mpdf:^version -w

Note: Put the word “version” instead (the version that matches your version)

Good luck everyone......

-1

are you using mpdf ver 7? if yes, you can change your code to

require_once APPPATH.'/third_party/mpdf7/vendor/autoload.php';
return new \Mpdf\Mpdf();

ref: https://mpdf.github.io/installation-setup/installation-v7-x.html

bungdito
  • 3,556
  • 4
  • 31
  • 38