PHP Html to Pdf Converter

Step 1: Preparation

Login to your CentOS 6.x machine.

Step 2: Install Dependencies

Now that I mentioned it, there are two items needed in order to install the wkhtmltopdf:

  1. xorg-x11-fonts-Type1
  2. xorg-x11-fonts-75dpi

Install the two items with the following command

yum install -y xorg-x11-fonts-75dpi
yum install -y xorg-x11-fonts-Type1

Step 3: Install wkhtmltopdf

Next, download the wkhtmltopdf RPM file.

wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

 

After the file has been downloaded, run the command:

rpm -Uvh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

 

Step 4: Testing

And now for the test. Run the command (and make sure that the computer is accessible to internet):

wkhtmltopdf http://www.google.com.ph google.pdf

During the generation, it will show something like this:

Loading pages (1/6)
Counting pages (2/6) 
Resolving links (4/6) 
Loading headers and footers (5/6) 
Printing pages (6/6)
Done

If the command generates the from the website to PDF file successfully, it is obvious that the wkhtmltopdf is working.

PHP USAGE

 echo exec('/usr/local/bin/wkhtmltopdf file.html file.pdf');