Guide to create mpdf in PHP

200OK Solutions Blog | Insights & Tutorials

Generate mPdf in PHP Without Using Composer

Share this post on:

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

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

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.

Heer Patel

Strategy & Growth Manager

4+ years experience
Business growth specialist
Go-to-market strategist
SME & startup scaling
Cross-functional leadership

Core Expertise

Business Strategy 95%
Growth Marketing 92%
Sales Enablement 90%
Partnership Development 88%
  • Growth: Customer acquisition, revenue growth, market expansion
  • Marketing: Digital campaigns, brand positioning, lead generation
  • Business Development: Strategic partnerships, B2B relationships, client success
  • Operations: Process optimization, KPI tracking, business performance
  • Product Strategy: Market research, customer insights, go-to-market planning
  • Leadership: Cross-functional collaboration, stakeholder management, execution
  • Technology: SaaS, software products, digital transformation
  • Hospitality: Hotel technology & operational growth
  • Retail: Customer acquisition & omnichannel strategy
  • Professional Services: Business consulting & digital growth
  • SMEs: Scaling businesses through strategic planning
  • Developing data-driven growth strategies
  • Aligning marketing, sales, and operations
  • Building sustainable customer acquisition systems
  • Driving partnerships that create long-term value
  • Using analytics to optimize business performance
  • Focusing on scalable and measurable growth

Heer Patel is a Strategy & Growth Manager with extensive experience helping startups, SMEs, and technology businesses achieve sustainable growth through strategic planning, customer acquisition, and operational excellence.

He specializes in business strategy, go-to-market execution, growth marketing, and partnership development, working closely with leadership teams to identify new opportunities, optimize business processes, and accelerate revenue growth.

With a strong understanding of market dynamics, customer behavior, and digital transformation, He has successfully led cross-functional initiatives spanning marketing, sales, product, and operations. he is passionate about building scalable growth systems, strengthening client relationships, and helping businesses turn ambitious goals into measurable results through data-driven decision-making and strategic execution.

    Reach Out Us


    Your name

    Your email

    Subject

    Your message