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 https://github.com/lynxbee/mpdf.git

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

$ vim mpdfexample.php

<?php
include("mpdf/mpdf.php");
$mpdf = new mPDF();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
?>

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

http://localhost/mpdfexample.php
Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home 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 NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) 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