12

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Hiro
  • 137
  • 1
  • 1
  • 7

2 Answers2

16

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)
Rakesh
  • 81,458
  • 17
  • 76
  • 113
0

If you just need to do it grammatically, why not use an external CLI tool like this:

os.system(r"ConvertPDFtoImage.EXE /S "C:\Input\Coffee.pdf" /T "C:\Output\Coffee.JPG" /C1  /1 * /5 200 /V")

for example in windows

user850498
  • 717
  • 1
  • 9
  • 22