Python Magickwand pdf to image converting and resize the image

user1725030 picture user1725030 · Oct 6, 2012 · Viewed 9.2k times · Source

I need to create thumbnails of pdf files, and I am using Imagemagick to achieve that.

I have tried Pythonmagick and wand to convert the pdf to an image. However, when I try to resize the converted pdf, the resulting image becomes black.

Is there any option to set -define pdf:use-cropbox=true using python wrappers?

Is there any other method in Python to convert a pdf to a thumbnail?

The code is as follows:

    import wand
    img = wand.image.Image(filename="d:\\test.pdf[0]")
    img.resize(160,160)
    img.save(filename="d:\\test.jpg")

Answer

user1725030 picture user1725030 · Oct 28, 2012

I found work around for this problem. Convert pdf into image 1st and save the image. open newly saved image and and resize it.

import wand
img = wand.image.Image(filename="d:\\test.pdf[0]")
img.save(filename="d:\\temp.jpg")
img = wand.image.Image(filename="d:\\temp.jpg")
img.resize(160,160)
img.save(filename="d:\\resized_image.jpg")

I am still waiting for better answer.