Outils pour utilisateurs

Outils du site


issue79:tutoriel_-_de_jpg_a_pdf_en_utilisant_imagemagick

Fear not Blender fans – Nicholas will return next month. Well, assuming his employer will actually give him a day off and some free time that is…

It's a common enough task, trying to convert multiple jpg files into one pdf, particularly when I don't need these to be converted with such high quality, I just want the black and white text readable.

I can scan, crop, and monochrome in a graphics program, but compiling them into a single PDF booklet was always tricky. Which is how I started using ImageMagick.

ImageMagick is a command-line conversion program that is capable of so many more batch operations than this - resizing, compression, format conversion - and it's available on all platforms - Linux, Windows and Mac.

Bear in mind that creating a PDF document from multiple JPEG images can take some time, and you may want to trial different settings for size and quality of output, so I suggest you make a copy of the JPEG files in a temporary folder to play around with and use Imagemagick on those – NOT on your originals. Reducing the resolution as a first step will also make things much quicker.

Originally I was just using the basic:

convert *.jpg output.pdf and/or convert *.jpg -adjoin output.pdf

which works most of the time. However, there's a bug in the convert routine which can in some versions give a segmentation fault when converting a number of JPEG files to one PDF file.

What this command does is take all the .jpg's (or format of your choice) in a folder, and convert them to a single PDF - you can name it whatever you like.

You can avoid the segmentation fault bug and do the compression at the same time if you use: convert *.JPG -compress Zip output.pdf

but the zip compression appears quite inefficient and results in huge file sizes.

You could resize and lower the quality of the images using:

mogrify -resize 50% -quality 25

Which overwrites the originals. You can combine resizing and conversion using:

convert -quality 25 -resize 50% *.jpg -adjoin output.pdf

which works, but takes longer as you're combining batch operations.

And yes, you can resizing images without overwriting the originals by specifying a new file name:

convert '*.JPG' -resize 640×480 newfile%03d.jpg

which outputs the converted images as newfile001.jpg, newfile002.jpg, and so on. Alternatively, if you want to retain the original filename and prepend “new”, you could use a bit more code:

for file in *.JPG ; do convert “$file” -resize 640×480 “new-${file}” ; done

This is just a sample of what Imagemagick can do if you are prepared to experiment at the command-line.

issue79/tutoriel_-_de_jpg_a_pdf_en_utilisant_imagemagick.txt · Dernière modification : 2014/01/21 12:08 de andre_domenech