Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import subprocess
  2. import shlex, os, glob
  3.  
  4. #ensure ImageMagick and Ghostscript are installed
  5. #tested on Python 2.7 / Windows XP
  6.  
  7. #this folder contains the convert.exe
  8. image_magick_path = "C:\\Program Files\\ImageMagick-6.6.7-Q16\\"
  9. os.chdir(image_magick_path)
  10.  
  11. #the folder containing the PDFs
  12. pdf_files_path = "D:\\Temp\\pdfs\\"
  13. pdf_files = glob.glob('%s*.pdf' % pdf_files_path)
  14.  
  15. #the folder to store the generated images
  16. output_path = "D:\\Temp\\thumbnails\\"
  17.  
  18.  
  19. #use the startupinfo to hide the Windows Shell
  20. startupinfo = subprocess.STARTUPINFO()
  21. startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW #subprocess.STARTF_USESHOWWINDOW
  22.  
  23. for pdf in pdf_files:
  24. filename = os.path.basename(pdf)
  25. #create a new output filename
  26. output_file = output_path + os.path.splitext(filename)[0] + ".png"
  27.  
  28. #this is the windows shell command
  29. command_line = """convert.exe -quality {quality} -border 3x3
  30. -bordercolor #000000 "{filename}"[0] -thumbnail 100x120 "{pngfile}" """.format(quality=100,
  31. filename = pdf, pngfile = output_file)
  32. args = shlex.split(command_line)
  33. #run the command
  34. proc = subprocess.Popen(args, stderr=subprocess.PIPE,
  35. stdout=subprocess.PIPE, stdin=subprocess.PIPE, startupinfo=startupinfo)
Add Comment
Please, Sign In to add comment