Image thumbnails and some bugfixes

Added splitting PDF to pages, creating a thumbnail. Cleaned up some non-DRY code and fixed a bug that could have led to the accumulation of useless files in /tmp. @pon @bsiddiqui @leore 
nice call here!