0
votes

I am trying to convert a PDF to JPG, main goal is to have a thumbnail so that the user can preview the PDF within the application.

Apparently ImageMagick is a good way to do this, yet so far I failed to get it to convert the file.

import subprocess

params = ['convert', '-density 300 -resize 220x205', 'dummy.pdf', 'thumb.jpg']
subprocess.check_call(params)

So this is what I am getting instead of having the file converted:

Unzulässiger Parameter - 300 Traceback (most recent call last): File "pdf_preview_test.py", line 4, in subprocess.check_call(params) File "C:\Users\EliasMessner\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 347, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['convert', '-density 300 -resize 220x205', 'dummy.pdf', 'thumb.jpg']' returned non-zero exit status 4.

I couldn't find any info about the problem. It looks like the "300" parameter is illegal but IMHO it is used correctly.. Help would be much appreciated. Thanks.

1

1 Answers

1
votes

As you are on Windows the code could be trying the built in Windows convert program. You do not say what version on Imagemagick you are using; V7 uses magick as opposed to convert which can prevent this problem.

If you allowed Imagemagick to add convert to the environmental path on install it would probably not be a problem - it never has for me on multiple installs.

You could try changing convert to the full path to convert surrounding the path in " ". You can rename the convert program e.g. myconvert and use that in the program rather than convert.

I would try a Imagemagick command out in the command line to prove it works as well first.