0

I try to find a simple python code that convert hundred of pdf files to jpg files to the same folder where the pdf files located. I use this code from Python Wand converts from PDF to JPG background is incorrect

from wand.image import Image
from wand.color import Color
import os, os.path, sys

def pdf2jpg(source_file, target_file, dest_width, dest_height):
RESOLUTION    = 300
ret = True
try:
    with Image(filename=source_file, resolution=(RESOLUTION,RESOLUTION)) as img:
        img.background_color = Color('white')
        img_width = img.width
        ratio     = dest_width / img_width
        img.resize(dest_width, int(ratio * img.height))
        img.format = 'jpeg'
        img.save(filename = target_file)
except Exception as e:
    ret = False

return ret

if __name__ == "__main__":
source_file = r"C:\Users\yaron.KAYAMOT\Desktop\aaa.pdf"
target_file = r"C:\Users\yaron.KAYAMOT\Desktop\aaa.jpg"

ret = pdf2jpg(source_file, target_file, 1895, 1080) 

but i get an error:

ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows
>>>

but i do have module MagickWand in the hard disk as shown in the cmd : enter image description here

UPDATE: when i try to pip install in the cmd "wand" module i get: enter image description here

so,i do have this module. When i try to pip install imagemagick \ ImageMagick i get: enter image description here

Community
  • 1
  • 1
user4989939
  • 349
  • 1
  • 3
  • 14

1 Answers1

0

You're importing from wand module. You probably haven't installed bindings for Python.

pip install Wand

See the details here: http://docs.wand-py.org/en/0.4.2/

Also try to do the following:

pip search pythonmagick

or something like that. Try to install all required packages. This may help you.

Community
  • 1
  • 1
Balas
  • 135
  • 8