5

So I'm using Wand to try to convert the PDF to an image

from wand.image import Image

with Image(filename="test.pdf") as img:
     img.save(filename="/temp.jpg")

with Image(filename="test.jpg") as img:
     img.resize(200, 150)
     img.save(filename="t.jpg")

but for some reason i get:

Traceback (most recent call last):
  File "C:\Users\Rafael\Desktop\k\pdf to image.py", line 3, in <module>
    with Image(filename="test.pdf") as img:
  File "C:\Python27\lib\site-packages\wand\image.py", line 2534, in __init__
    self.read(filename=filename, resolution=resolution)
  File "C:\Python27\lib\site-packages\wand\image.py", line 2601, in read
    self.raise_exception()
  File "C:\Python27\lib\site-packages\wand\resource.py", line 222, in raise_exception
    raise e
DelegateError: PDFDelegateFailed `The system cannot find the file specified.

' @ error/pdf.c/ReadPDFImage/798

Can i do something or is there another way to convert a pdf to an image?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Rafas
  • 103
  • 1
  • 2
  • 7
  • Are you sure the path is "test.pdf"? IT sounds the like the file doesn't exists, or the program cannot see it from the current directory. – Jerfov2 May 18 '16 at 12:33
  • Yeah i'm sure i even tried the full path – Rafas May 18 '16 at 12:34
  • Seems that ImageMagick isn't configured ``--with-lqr`` option. Make sure your versions of python and ImageMagick are indeed the same(32/64 bit). If there's a conflict in the versions, uninstall ImageMagick and install the compatible one. – Nickil Maveli May 18 '16 at 13:22
  • I checked and both are 64 bit – Rafas May 18 '16 at 13:41
  • Possible duplicate of [PythonMagick can't find my pdf files](https://stackoverflow.com/questions/13984357/pythonmagick-cant-find-my-pdf-files) – Basj May 22 '18 at 21:38

4 Answers4

2

Installing Ghostscript and adding

C:\Program Files (x86)\gs\gs9.06\bin

to your systempath should help to resolve this issue as it helped me to overcome this error....

zx485
  • 28,498
  • 28
  • 50
  • 59
Abhishek Jain
  • 3,815
  • 2
  • 26
  • 26
1

The reason may be a missing ghostscript installation. This is a similar question on SO

Community
  • 1
  • 1
Peter Clause
  • 1,132
  • 9
  • 22
0

There is another way. Looks like you are using windows so you need download "https://github.com/oschwartz10612/poppler-windows/releases/" Because you are using Windows,so you need to state the path to poppler/bin folder: code:

from pdf2image import convert_from_path

poppler_path = "C:\path\to\poppler\bin"

images = convert_from_path('example.pdf')

for i in range(len(images)):

  
    images[i].save('page'+ str(i) +'.jpg', 'JPEG')

reference : https://www.geeksforgeeks.org/convert-pdf-to-image-using-python/

0

My favorite way to do this is using PyMuPDF

Install package

pip install PyMuPDF

Usage

import fitz  # installed via pymupdf!

# To get higher resolution
zoom_x = 2.0
zoom_y = 2.0
matrix = fitz.Matrix(zoom_x, zoom_y)

doc = fitz.open("becomes-black.pdf")
for page in doc:
    pix = page.get_pixmap(matrix=matrix)
    pix.save(f"page-{page.number}.png")
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958