user1977108
user1977108

Reputation: 21

convert PDF into TIFF with 600dpi and jpg 96 dpi

I want to convert pdf into tiff with 600 dpi and jpg with 96 dpi from Python script using ImageMagick.

i was done this task using (imagemagick) command line but i want to convert pdf into tiff and jpg using Imagemagick in python ,

can you please help me for that......

Upvotes: 2

Views: 11302

Answers (2)

furins
furins

Reputation: 5048

First you have to load a wrapper around imagemagick library

using PythonMagick:

from PythonMagick import Image

or using pgmagick:

from pgmagick import Image

then, independently from the library you loaded, the following code will convert and resize the image

img = Image()
img.density('600')  # you have to set this here if the initial dpi are > 72

img.read('test.pdf') # the pdf is rendered at 600 dpi
img.write('test.tif')

img.density('96')  # this has to be lower than the first dpi value (it was 600)
# img.resize('100x100')  # size in px, just in case you need it
img.write('test.jpg')  


# ... same code as with pythonmagick 

Upvotes: 3

Rakesh
Rakesh

Reputation: 82765

You can use the subprocess module to execute the imagemagick command

import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)

Upvotes: 1

Related Questions