I have installed python-ghostscript on Linux. I can run gs from the command line and it will create a jpg from a pdf. Here is the code that works:
~$ gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -sOutputFile=/home/user/output.jpg /home/user/downloads/test.pdf
I am trying to run that process in Python but I cannot get the syntax. I get no errors, but nothing happens. I've tried to read up on Popen/subprocess, but I'm not understanding why the gs process that I am calling doesn't run and create the file.
output = Popen(['gs','-dSAFER','-dNOPAUSE','-dBATCH','-sDEVICE=jpeg','-sOutputFile=/home/user/output2.jpg /home/user/downloads/test.pdf'])
Your last two parameters are joined, so it can't work; it's effectively the same as running in your terminal gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg '-sOutputFile=/home/user/output.jpg /home/user/downloads/test.pdf', which you wouldn't expect to work.
Separate those last two and it should work:
output = Popen(['gs', '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=jpeg', '-sOutputFile=/home/user/output2.jpg', '/home/user/downloads/test.pdf'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With