Convert Multi File of PNM to PDF

Convert Multi File of PNM to PDF

I have lots of pnm which is scanned files. PNM is picture format. I need to make them into one file. The only way is convert them into pdf. And make them into one file.

Linux provides such command. Which is convert command. The syntax is simple like this :

#convert source.pnm output.pdf

The problem is I have 40 file that I need to convert. Is there a way to make automation to do the process in single command? Yes of course. A guy in this forum suggested to create bash script. Here one inside the bash :

#!/bin/bash
for f in *.pnm; do
	convert ./"$f" ./"${f%.jpg}.pdf"
	echo ./"$f"  "berhasil"
done

I named the bash script convert_all.sh. And make it executable by adding chmod.

#chmod +x convert_all.sh

Then I put it in the pnm directory and execute it.

#./convert_all.sh

It works like a charm.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.