Tuesday, May 12, 2015

Easy 5 steps to get thumbnails out of Pdf using Python

Be The First To Comment
1) Install Ghost script before python dependencies installation from: http://www.a-pdf.com/convert-to-pdf/gs.exe

2) Make yourself familier with Wand, a ctypes-based simple ImageMagick binding for Python.

3) Install Wand - pip install wand

4) Use the following script..
 #Install Ghost script before python package's installation   
 #from: http://www.a-pdf.com/convert-to-pdf/gs.exe  

 from wand.image import Image  
 from wand.display import display  
 fileDirectory = "D:/files/"  
 inFileName="myInputfile.pdf"  
 outFileName="myOutputfile.png"  
 imageFromPdf = Image(filename=fileDirectory+inFileName)  
 pages = len(imageFromPdf.sequence)  
 print(pages)  
 image = Image(  
   width=imageFromPdf.width,  
   height=imageFromPdf.height * pages  
 )  
 for i in range(pages):  
   image.composite(  
     imageFromPdf.sequence[i],  
     top=imageFromPdf.height * i,  
     left=0  
   )  
 image.format="png"  
 image.save(filename=fileDirectory+outFileName)  
 display(image)  



5) Let me know if you have any trouble.

 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me