I've downloaded and installed PythonMagick for python 2.7, 64 bit Windows 7, from the Unofficial Windows Binaries.
I am trying to run this code (Processor.py)
import PythonMagick
pdf = 'test.pdf'
p = PythonMagick.Image()
p.density('600')
p.read(pdf)
p.write('doc.jpg')
within this folder (D:\Python Projects\Sheet Music Reader)
However, using that relative pdf path or pdf = "D:\\Python Projects\\Sheet Music Reader"
results in this error;
Traceback (most recent call last):
File "D:/Python Projects/Sheet Music Reader/Processor.py", line 6, in <module>
p.read(pdf)
RuntimeError: Magick: PostscriptDelegateFailed `D:\Python Projects\Sheet Music Reader\test.pdf':
No such file or directory @ error/pdf.c/ReadPDFImage/664
I simply don't understand why it can't find my pdf; it's in the same directory as the python script.
What's causing this error, and how do I fix it?
(I've on the impression that converting pdfs to images in python is a night mare)
I had exactly the same problem couple of days ago. While converting from .gif (oder something else) to .jpg worked really fine, converting from .pdf to .jpg produced exactly the same error. Thats happing because ImageMagick uses Ghostscript for reading/converting PDFs.
You can solve the problem by installing Ghostscript (only 32-bit version works). Don't forget to add "C:\Program Files (x86)\gs\gs9.06\bin" to your systempath.
Here a step-by-step-guide how I was getting PythonMagick work:
(I'm using Python 2.7.3 32-bit on Windows 7 64-bit.)
DON'T forget to check the option "Install development headers and libraries for C and C++".
C:\Program Files (x86)\ImageMagick-6.8.1-Q16
).Additional set this path to your systemwide-path at the very first position if it isn't already there.
Set
C:\Program Files (x86)\gs\gs9.06\bin
to your systemwide-path, right after ImageMagick.convert some.pdf some.jpg
in the command line. If it doesn't work you've done something wrong at point 1-3.(Again: I'm using the 32-bit Python 2.7.3 interpreter, so I took "PythonMagick-0.9.7.win32-py2.7.exe" for that.)
Additional an example for a PDF with multiple pages:
That's the only workaround for that problem which comes into my mind.