Posted by: h4ck@lyst | February 19, 2009

How to convert jpegs into pdf using command line in linux.

convert *.jpg new.pdf

An easy GUI way of converting your images into pdf is to use openoffice. Insert the image into a text document in openoffice, save the file and then export it into pdf.

However it could be a royal pain if you have a multitude of images. Like I take photographs of notes rather than getting them photocopied. Now all digi cams give you serial numbered pics and that makes life much easier.

First and foremost you can rotate your pics using convert or mogrify. The difference between the two being that convert creates a copy of the image whereas mogrify works upon the original image itself.

mogrify -rotate 270 *
Am assuming you are in the folder containing all the pics that you have to work upon.

You can reduce the image size as well coz very rarely you will be needing the high resolution pics in pdf.

mogrify -resize 33% *

Now you need convert the jpegs to pnm

for i in `ls`;do jpegtopnm $i $i.pnm;done

Now convert the pnm s to ps

for i in `ls *.pnm`;do jpegtopnm $i $i.ps;done

Now convert the ps to pdf

for i in `ls *.ps`;do ps2pdf $i $i.pdf;done

Now all thats needed is to join the indivdual pdf s into one

pdfmerge *.pdf output.pdf

Thats it! Bingo you have just converted all your scanned images into a clean pdf 🙂

PS: Assumption made in here is that your pdf files are named in an alphanumeric order that corresponds to the sequence in which the pages need to be in the final pdf. Another assumption is you are on a linux machine with all the above installed or with means of doing so. Windows people kindly excuse.

End of the day you can always play around and find better, easier tools. But nothing beats the command line geekiness and ease 🙂

Advertisements

Responses

  1. I guess pragyan 09 made u do all these 😛

    • ha ha.. no da.. rather it was the boredom after pragyan + its-the-night-before-cycle-tests-where-are-my-notes-syndrome..


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: