Perl
--
Questions
--
Followers
Top Experts
We've no more time to spend searching for a solution because bug is too old now :(.
SO let's start with a perl or python script. Please help me to write a script according to specs below :
- choice of perl or python will be done according to easiest way to install and configure perl/python for a web server and restrict to some directory only on a VirtualHost apache conf.
- script will be called from an GET HTTP call.
- arguments of script are:
* docroot relative path of source pdf file
* docroot relative path of a destination lowres folder
* docroot relative path of a destination thumbnail folder
e.g. http://my.project.com/foo/convertpdf.pl?src=data/upload/ftp/blah/myfile.pdf&lowres=/data/upload/_LOWRES/ftp/blah&thumb=/data/upload/_THUMB/ftp/blah
- script will produces 2 jpg images from 1st page of the pdf:
* lowres file will be jpeg of 1st pdf page with max size = 220x220 pixels. w/h ratio of pdf page is preserved of course.
* thumb file will be jpeg of 1st pdf page with max size = 48x48 pixels. w/h ratio of pdf page is preserved of course.
Could you help me to solve this ?
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
http://www.weenysoft.com/free-pdf-to-image-converter.html
Thanks
I suggest to use the matured ImageMagick (http://www.imagemagick.org/) set of utilities. The one you want is named convert. You can use the PythonMagick (http://www.imagemagick.org/download/python/) wrapper.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
1)script will be called from an GET HTTP call ( check a specs above).
2) we not working on window platform.
and the tool suggested by @Dushan911 is .
Free PDF to Image Converter works on Windows XP, Windows Vista, Windows 7 and Windows 8, both 32-bit and 64-bit versions.
Thanks
import PythonMagick
img = PythonMagick.Image('a.pdf') # use your full path here
img.write('original.jpg')
imgLowRes = PythonMagick.Image(img) # make a copy
imgLowRes.resize('220x')
imgLowRes.write('lowRes.jpg')
img.resize('48x')
img.write('thumb.jpg')
Why the produce images are in black.?
Thanks

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Also, img = PythonMagick.Image('a.pdf[0]') -- notice the zero in the brackets--will extract the first page.
- script will produces 2 jpg images from 1st page of the pdf:
* lowres file will be jpeg of 1st pdf page with max size = 220x220 pixels. w/h ratio of pdf page is preserved of course.
* thumb file will be jpeg of 1st pdf page with max size = 48x48 pixels. w/h ratio of pdf page is preserved of course.
Could you improve that
#!c:/Python27/python.exe -u
import PythonMagick
img = PythonMagick.Image('Hello.pdf') # use your full path here
img.write('original.jpeg')
imgLowRes = PythonMagick.Image(img) # make a copy
imgLowRes.sample('220x')
imgLowRes.write('lowRes.jpeg')
img.sample('48x')
img.write('thumb.jpeg')
From that script still produces images in bad quality.
Any idea?
Thanks
#!python3
import os
import PythonMagick
def smallAndThumbnail(fname, smallpath, thumbnailpath):
name, ext = os.path.splitext(os.path.basename(fname))
smallfname = os.path.join(smallpath, name + '.jpg')
thumbfname = os.path.join(thumbnailpath, name + '.jpg')
img = PythonMagick.Image() # empty object first
img.density('300') # set the density for readeing; must be as a string
img.read(fname + '[0]') # read the first page of PDF
# Background color.
bgcolor = 'white' # can have the form '#ffffff'
# The small image first.
geometry = '220x220'
imgResult = PythonMagick.Image(geometry, bgcolor) # init -- the square of the colour
imgCopy = PythonMagick.Image(img) # make a copy
imgCopy.sample(geometry)
imgResult.composite(imgCopy,
PythonMagick.GravityType.CenterGravity,
PythonMagick.CompositeOperator.CopyCompositeOp)
imgResult.write(smallfname)
# The thumbnail.
geometry = '48x48'
imgResult = PythonMagick.Image(geometry, bgcolor) # init -- the square of the colour
imgCopy = PythonMagick.Image(img) # make a copy
imgCopy.sample(geometry)
imgResult.composite(imgCopy,
PythonMagick.GravityType.CenterGravity,
PythonMagick.CompositeOperator.CopyCompositeOp)
imgResult.write(thumbfname)
if __name__ == '__main__':
smallAndThumbnail('./pdf/a.pdf', './small', './thumbnail')






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Perl
--
Questions
--
Followers
Top Experts
Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.