If you want to use mPDF without Composer’s intervention inside your
CodeIgniter project, then here are the steps to follow to download mPDF
manually and use it in a CodeIgniter application.
Step 1: Download mPDF
To get the latest version of mPDF without using Composer, you can manually download it
from the mPDF GitHub repository. Here are the steps to do so:
- Visit the mPDF GitHub repository.
- GitHub – mpdf/mpdf: PHP library generating PDF files from UTF-8 encoded HTML
- Click on the “Code” button and select “Download ZIP”.
- Unzip the downloaded file to your desired directory.
Step 2: Include mPDF in Your Project
Move the mpdf directory to your project directory where you want to use mPDF.
![guide to mpdf directory](https://blog.200oksolutions.com/wp-content/uploads/2024/07/Screenshot-2024-07-22-124158.webp)
Step 3: Autoload Dependencies
mPDF requires some dependencies which are managed by Composer, but since
you’re not using Composer, you need to manually include the autoload file.
In your project, create an autoload.php file and include the necessary dependencies
like this:
Step 4: Using mPDF in CodeIgniter
You can now start using mPDF in your project. Here’s a simple example of how to
use mPDF to generate a PDF in a CodeIgniter controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
// Include the mPDF autoload file
require_once APPPATH . 'third_party/autoload.php';
class PdfController extends CI_Controller {
public function index()
{
$pdf = new \Mpdf\Mpdf();
// Set the header
$pdf->SetHeader('header');
// Write HTML content to the PDF
$pdf->WriteHTML('Hello World');
// Set the footer
$pdf->SetFooter('footer');
// Clear output buffer
ob_end_clean();
// Output the PDF
$pdf->Output('genpdf_view.pdf', 'D');
}
Output: –
![output of tmpdf in php](https://blog.200oksolutions.com/wp-content/uploads/2024/07/Screenshot-2024-07-22-124733.webp)
Advantages of Using mPDF Without Composer in CodeIgniter :-
- .No Dependency on Composer.
- Greater Control Over Dependencies.
- Reduced Disk Space and Resource Usage.
- Enhanced Security.
Conclusion: –
By following these steps, you should be able to use the latest version of mPDF
in your CodeIgniter project without using Composer.
If you encounter any issues with dependencies, you might need to manually
download and include those as well. This approach ensures you have full
control over your mPDF integration and can easily customize it to fit your
project’s needs.