Merge multiple PDFs using Ghostscript

Posted in: linux |  

1 Aug 2011

Merging multiple PDF is not a common task, but it is good to know how to do it once the requirement arises. Specially if you want to merge documents from within a language like PHP. Although there are a few PHP classes that do the job, many throw out errors due to incompatibility between different versions of PDF and the compression used thereof. The last good (and free) solution I found was that of using Ghostscript to merge the PDF’s, and calling the command from PHP.

A simple Ghostscipt command to merge two PDFs in a single file is shown below.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combine.pdf -dBATCH 1.pdf 2.pdf

Search-engines have reached a impasse with respect to understanding of HTML data. Although most sites, especially databases centric sites use structured data in the backend, once the data is rendered as HTML the data looses all its structure and makes it difficult for search engines to understand them correctly. Until now most search engines have relied on extracting keyword text from the web pages and ranking the pages accordingly, taking the context around the keyword into consideration. This obviously has its limitations and it can only take you so far.
Read More

The following is a very short code to read the version number of a PDF document using PHP. I needed this recently during a PDF processing app developed in PHP. As Adobe uses different compression methods in various versions, it becomes necessary to be able to identify the version of the PDF under work.
Read More

Tail functionality in PHP

Posted in: php,tip |   ( 6 ) Comments

18 Jul 2011

Frequently one needs to get the last few lines of some log files, whether php error logs or Apache logs. Most of these file sizes run into megabytes, which makes it difficult and time consuming to remotely open them using ftp. If you have shell access then you can easily use the *nix ‘tail’ command to return the last ‘n’ lines; or one can use the following if shell access is not enabled on your hosting.

function Tail($filename) {
  return system('tail -n 20 '.$filename);
}

Read More

JavaScript Photo galleries are dime-a-dozen, with a large number of variations in size and features. But this particular one developed using Mootools is a breath of fresh air. Most galleries are spatially bounded, i.e. they have a limit how how much you can scroll in any direction.
Read More

During a recent project I needed a database of IATA airport codes. Airports around the world are universally known by a unique three-letter code: the “International Air Transport Association (IATA) Location Identifier”. It is much easier for pilots, travel agents, frequent flyers, baggage handlers and anyone having anything to do with airlines to say and write LGA then the full “New York, NY – La Guardia Airport“.
Read More

In a previous post we saw how to detect human faces in images using JavaScript. In the current post we will look into a PHP port of a JavaScript face detection algorithm without using openCV. Since the code is completed written in PHP it cannot attain the raw speed that C,C++ provides, but for many trivial application a PHP version can do.
Read More

Retrieving email Gravatar images

Posted in: php |  

30 Jun 2011

Below is a quick hack to retrieve and save Gravatars. Gravatar images come in various formats, but we don’t detect them here, just save the retreived image in ‘jpg’ format.
Read More

In the previous post we saw how we can generate a screenshot from a url. In this post we will see how we can create a color palette of the screenshot (or any other image for that matter) using PHP and GD. This can be useful if you need to quickly get the color scheme of a website or a image. Below are a few example images and their palettes generated using the program.
Read More

Taking screenshos of websites is not a frequent requirement for developers but can come handy on many occasions. Although there are some nice solutions on the web, a particular one I found very good is wkhtmltoimage.

wkhtmltoimage is a simple shell utility which can be used to convert html to images using the webkit rendering engine, and qt.
Read More