Wednesday, July 18, 2012

Convert HTML to PDF using WKHTMLTOPDF


I was looking for solution to generate the PDF from dynamic HTML in last week. I was looking for easy way to generate the PDF without being affected with syntax and design.

While goggling I found the tool: WKHTMLTOPDF  

This tool is converting HTML (CSS support) to PDF the same way you save a PDF from browser.

Here are the steps to install and integrate the tool.

First, install the webkit library on your server.

$ wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.8.3-static.tar.bz2
$ tar -jxvf wkhtmltopdf-0.8.3-static.tar.bz2
$ sudo aptitude install ia32-libs

Make symbolic link to tool in /usr/local/bin

$ sudo ln -s /full_path/WKHTMLTOPDF /usr/local/bin/WKHTMLTOPDF

Now we are ready to useJ.

Now try the following command to convert the google page into PDF:

$ wkhtmltopdf http://www.google.com example1.pdf

There are many options where you can generate the different size/types of PDF like A4, A2 etc

Here are few examples:

$ wkhtmltopdf http://www.google.com examplea1.pdf -s A4

$ wkhtmltopdf http://www.google.com examplea2.pdf -s A2

Wednesday, July 11, 2012

Increase size of the file system in AWS


Assuming that you are using a linux AMI, in your case you have an easy method for increasing the size of the file system:

1) Stop the instance
2) Detach the root volume
3) Snapshot the volume
4) Create a new volume from the snapshot using the new size
5) Attach the new volume to the instance on the same place where the original one was
6) Start the instance, stop all services except ssh and set the root filesystem read only
7) Enlarge the filesystem (using resize2fs command) and/or the partition if needed
8) Reboot

As an alternative you can also launch a new instance and map the instance storage or you can create a new ami combining the two previous steps.

Install GD Library and ImageMagick on Linux server


Most scripting language is mostly used to manipulate and create image files in various different image formats including GIF, PNG, JPEG, etc. with the help of GD. Also scripting language can output image streams directly to a browser.

ImageMagick is an open source software suite for displaying, converting, and editing raster image files.

Following are the steps to install GD library:

Step 1: $ yum install php-gd
Step 2: $ yum install glib
Step 3: $ yum install glib2
Step 4: $ yum install libpng
Step 5: $ yum install libjpeg
Step 6: $ yum install libtiff
Step 7: $ yum install ghostscript
Step 8: $ yum install freetype


Following are the steps to install ImageMagick:

Note: Download ImageMagick.tar.gz from www.imagemagick.org or a mirrors and verify its message digest.

Step 1: $ tar xvfz ImageMagick.tar.gz
Step 2:
$ cd ImageMagick-[VERSION]
Step 3:
$./configure
Step 4:
$ make
Step 5:
$ sudo make install
Step 6:
$ sudo ldconfig /usr/local/lib

Great :) Now ImageMagick is installed on your server. 


You can verify the installation by following Commands:

$ /usr/local/bin/convert logo: logo.gif
$ make check