Matrix of several individual pdf and image files (Linux & Mac)

Suppose we have several individual pdf files such as 1.pdf, 2.pdf, 3.pdf and so on. Now we want to put them in a matrix form similar to many subplots in a figure. Following is the step by step procedure to make such a single matrix of all those pdf files.

At first step, I would like to remove all excess white space from my individual pdf files using command line option (each file at a time or if all files having some systematic nomenclature, follow my blog post here).

$pdfcrop 1.pdf

Once we have all the cropped (ready to use) pdf files, we will first combine them in a single pdf file (serial arrangement of individual files matter).

$pdftk 1.pdf 2.pdf 3.pdf 4.pdf cat output 1234.pdf

Now we have a pdf file with 4 pages and contains all 4 individual pdf files. Lets say now we want to make a 2×2 matrix of pdf files.

$pdfnup 1234.pdf –nup 2×2

The above command will make a pdf with 4 individual figures in 1 pdf file in a matrix form provided by user. One can again crop the output pdf file to remove its excess white space.

If we have individual images even then we can use “montage” of the imagemagick package.

montage frame_[0-8].png -geometry 600×600+2+2 -tile 3×3  montage_geom1.png

This command will use images frame_0.png to frame_8.png to form a tile of 3×3 as an output image. Other features can be searched on imagemagick website.