Create a pdf from php / html using mpdf

This article will explain, how to create a pdf file using mpdf from html / php.

Install php if you are working on local ubuntu machine, on shared hosting mostly php will have been installed.

Below command will install php5 on ubuntu 14.04,

 sudo apt-get install php5

If you are using ubuntu 16.04, it comes with php7, which we can install using below steps,

sudo apt-get install libapache2-mod-php
sudo apt-get install php-mbstring

Download mpdf code from website,

 cd /var/www/html
 git clone

Here, we will try to create a sample example in localhost, so we will need to move this code to localhost,

$ vim mpdfexample.php

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

Now, open this php file at localhost in browser as,

Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Moodle NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded
Tags: , ,

Leave a Reply / Ask Question