6/29/2009

nautilus script : make PDF thumbnail to png file

* requirements :
1. python
2. gmessage (sudo apt-get install gmessage)
3. ImageMagick (sudo apt-get install imagemagick)

* source file : ~/.gnome2/nautilus-scripts/thumbnail_pdf.py (file mode 755)


#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os #, glob

PDFextensions = ['.pdf', '.PDF', '.Pdf']

def showme(s):
# for easy debugging, gmessage is used
os.system('gmessage -center ' + str(s))

def MakePDFThumbnail(filename):
os.system('convert -sample 50%x50% +append "' + filename + '" "' + filename + '.png"')
# convert command from imagemagick are used here.
# -sample 50%x50% --> 50% downsizing the pdf file
# +append --> horizontally appending option. If one want a vertical appending, -append option will do

tmp = os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS']
fns = tmp.split('\n')
#showme(len(fns)) # for debugging

for f in fns:
filename, fileext = os.path.splitext(f)
if fileext in PDFextensions :
MakePDFThumbnail(f)

ref : http://www.imagemagick.org/script/convert.php

댓글 없음: