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 [ Note: this article mentions steps as followed on Ubuntu 14.04 which was latest stable Ubuntu version at the time of writing this article , please use updated versions as required and are available ]

$ 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 Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images 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 User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded
Tags: , ,

Leave a Reply / Ask Question