Welcome Guest, Not a member yet? Register   Sign In
[Solved] Implement Mpdf
#1

(This post was last modified: 01-26-2020, 06:38 AM by PHS.)

Hello friends!

I'm trying to implement the mpdf library in CodeIgniter 4 like this:

Accessing App/Config/Constants.php includes the line of code:

Code:
defined('MPDF') || define('MPDF', ROOTPATH . 'vendor/autoload.php');


In the App/Config/Autoload.php file, I added one more element to the psr4 array:


Code:
$psr4 = [
'Config'       => APPPATH. 'Config',
APP_NAMESPACE => APPPATH,
'App'          => APPPATH,
'Mpdf'         => APPPATH. 'Libraries',
];

In the App/Libraries file, I created a class to instantiate Mpdf:


Code:
<?php namespace App\Libraries;

class Mpdf {

     public $method;

     function __construct() {

           require_once MPDF;

           $this->method = new \Mpdf\Mpdf (['mode' => 'utf-8']);
      }
}


In the Controller, I'm calling the Mpdf class like this:


Code:
use App\Libraries\Mpdf;

....

public function witeForm() {

     $mpdf = new Mpdf();
     $mpdf->method->WriteHTML('Hello  World');

      return $mpdf->method->Output();
}


But the displayed page is corrupted, as seen in the link below. 

Image corrupt

My question is: what is the correct way to implement Mpdf in CodeIgniter 4?

Note: I included Mpdf to the project via Codeigniter composer

Thanks in advance!
Reply


Messages In This Thread
[Solved] Implement Mpdf - by PHS - 01-25-2020, 07:21 PM
RE: Implement Mpdf - by jreklund - 01-26-2020, 12:48 AM
RE: Implement Mpdf - by PHS - 01-26-2020, 06:36 AM
RE: [Solved] Implement Mpdf - by jreklund - 01-26-2020, 12:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB