i want to convert my pdf files with ImageMagic python module PythonMagick but i havent found any solution on net.

import PythonMagick
im = PythonMagick.Image('files.pdf')

i am using below code and it returns only first page of my pdf file.

any help would be greatly appreciated

4 Years
Discussion Span
Last Post by AdeleB

since there really isnt a whole lot of documentation (at least that I could find) I will make an assumption --
PDF files are basically a collection of "pages" and it seems that you are simply running the create image function on the first "page"

I would encourage you to find a way to break apart the pages of the pdf, and run the image creation individually....

you can probably try...

from pyPdf import PdfFileReader
from PythonMagick import Image

myfile = PdfFileReader('files.pdf')
pages = myfile.getNumPages()

for page in pages:
    im = Image(myfile.getPage(i+1))

Now.. Im a bit of a newb with Python... so.. would be interested to know if I figured that out right.. You may have to download the PyPdf package to make it work, though...



Here is how I split a pdf file into pages from python by calling pdftk

pdf_name = "foo.pdf"
ndigits = 2
com_line = "pdftk A={src} burst output {dst}".format(
        src = pdf_name,
        dst = "%0{ndigits}d.pdf".format(ndigits=ndigits))
subprocess.call(com_line, shell=True)

Edited by Gribouillis


cant figure out how to edit my post... so...
I made a boo boo..

change 'i+1' to 'page+1' in both instances, assuming my script works in the first place...

and the more I look at it, I think pages would be an int... so the for line should read:

for page in range(pages):

Edited by ryantroop: bad coding :( Sorry


I'm not a developer, i always use this <snip> to convert pdf to image online.

Edited by Gribouillis: irrelevant and spammish

irrelevant and spammish
This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.