0

I have much trouble to have a code to convert pdf file to png on python 3.6, windows 10.

I know what you are going to say : google it !

But barely everything I've found was on python 2.7. And some packages haven't been updated.

What I've seen so far it's that the best way to do it is using Wand, right ? (I have installed ImageMagick before )

from wand.image import Image
# Converting first page into JPG
with Image(filename='0.pdf') as img:
    img.save(filename="/temp.jpg")
# Resizing this image

Here was my second error :

wand.exceptions.DelegateError: PDFDelegateFailed 
`The system cannot find the file specified.' @ error/pdf.c/ReadPDFImage/809

So i read i need ghostscript. I installed it. But the package is for python 2.7 and it doesn't work. I found python3-ghostscript 0.5.0. https://pypi.python.org/pypi/python3-ghostscript/0.5.0

New error :

RuntimeError: Can not find Ghostscript DLL in registry

So here I needed to install Ghostscript 9 : https://www.ghostscript.com/download/gsdnld.html


First of all it's not a GPL license ... That's not even a package but a program. I don't know how I can use it in my futures python codes...


and there is still an error :

RuntimeError: Can not find Ghostscript DLL in registry

and i can't find anything for it.

el Josso
  • 159
  • 2
  • 16

1 Answers1

0

Ghostscript is licensed under the AGPL, the licence can be found in /Program Files (x86)/gs/gs9.21/doc if you want sources then they are available from the Ghostscript Git repository. Note I'm assuming you are running on Windows since you refer to the Registry.

If you install the prebuilt binary then it will create an entry in the Windows Registry, I assume that's what your Python code is looking for but I can't be sure. You should make sure you install the correct word size (32 or 64) version required by Python, if it cares.

You can, of course, simply run Ghostscript to render a PDF file and produce PNG output.

gswin32c -sDEVICE=png16m -sOutputFile=out%d.png input.pdf

This will create one file per page of the input PDF file, use gswin64c for the 64-bit version...

You can alter the resolution of the output with the -r switch, eg -r300

I presume you can simply fork a process from Python. Otherwise you'll have to get someone to tell you what the Python script is looking for in the Registry. Perhaps its looking for a specific version of Ghostscript, or the 32-bit version or something.

KenS
  • 30,202
  • 3
  • 34
  • 51