Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PDF thumbnail preview generation

I am looking for ways to generate jpeg thumbnail of pdf files. I would like to do that in Python. Is there any library or can anyone guide me how to do it?

Thanks

I am working on MacOS X Lion. But I would like to run it on Ubuntu or CentOS.

like image 877
Hiro Avatar asked Apr 10 '12 05:04

Hiro


1 Answers

You can use ImageMagick {apt-get install imagemagick on Ubuntu} (it also has Python lib PythonMagick) to convert pdf to images

import subprocess
params = ['convert', 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)

You can also provide parameters at which the image has to generate out of the pdf like

params = ['convert', '-density 300 -resize 220x205', 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
like image 182
Rakesh Avatar answered Oct 04 '22 02:10

Rakesh