convert PDF into TIFF with 600dpi and jpg 96 dpi
10,548
Solution 1
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
Solution 2
You can use the subprocess module to execute the imagemagick command
import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
Author by
user1977108
Updated on June 04, 2022Comments
-
user1977108 almost 2 years
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......
-
user1977108 about 11 yearsbut i just want convert pdf to tiff and jpg using imagemagick,, not using python interface for imagemagick (pythonmagick)...
-
furins about 11 yearsso I think Rakesh answer is what you're looking for :)
-
Amadeus about 4 yearsI tried to add PyhtonMagick library but it is not available. Anybody was able to get it?
-
furins about 4 years@Amadeus: PythonMagick is an old library so I've added a more recent alternative, PgMagick, that is better documented and should be easier to install. Hope it helps.
-
Amadeus about 4 years@furins I found another solution but I will mark your answer for future use. Thanks for the reply!