Bash - Make PDF

0 Likes

Creating one pdf file from a directory of multiple .png scans.




Using kooka and my Cannon scanner, I have been scanning some articles into
my computer, these usually require several pages of scans, and I save the
images as .png files. Kooka saves the images in the format kscan_0001.png
, kscan_0002.png , and so on. As long as you scan in pages in the same
order you want them in the pdf, you won't have any need to re-number the
scanned image files. (You could save the scanned files in almost any image
format you wish. Simply change the script to work with the image format
you want to work with.)



The goal was to get ONE pdf document that was cross platform compatible
created from the multiple scans... all with minimal effort on my part
other than the scanning. Using bash, I created a quick script to do the
repetitive work.



What it does:

First it takes .png scans from the current directory and creates a .pdf
file for each one with imagemagick.

Then, with pdftk, all the .png scans are rolled into one larger .pdf file.



Code:



--------------------------------------------------------------------

#!/bin/bash
# FILE : makepdf.sh
# Function: Creates ONE pdf file from a directory of multiple png scans.
# Copyright (C) 2006 Dave Crouse <dave NOSPAMat usalug.org>
# ----------------------------------------------------------------- #
#
# NOTES:
# Scans must be in .png format, or change the imagetype variable.
# Converts each png image file to a pdf file.
#

#######################
# VARIABLE: Change this to jpg, bmp, or whatever image file type your
converting from.
imagetype="png"
#######################

# Test to make sure required programs are installed.
if -z $( type -p convert ); then echo -e "ImageMagick -- NOT
INSTALLED !";exit ;fi
if -z $( type -p pdftk ); then echo -e "pdftk -- NOT INSTALLED
!";exit ;fi

read -p "What would you like to name your new pdf file ? :" newname;
for i in *.${imagetype} ; do convert $i $i.pdf;done;
pdftk *.pdf cat output $newname.pdf;
for i in *.${imagetype} ; do rm -f $i.pdf;done;
echo "Conversion complete. PDF file ${newname}.pdf created.";

exit

--------------------------------------------------------------------


In my .bashrc file I have added:



alias makepdf='sh /home/crouse/Scripts/makepdf.sh'


From the bash shell, I just go into the directory where the scanned images
are, and type "makepdf" and create a pdf file with all the .png images in
that directory. Makes creating a pdf from multiple scans painless.



For more info on the required programs:



Pdftk - is a command-line tool for manipulating PDF documents.

Home Page: http://www.accesspdf.com/pdftk/

Suse

Page: http://www.novell.com/products/linuxpackages/professional/pdftk.html



ImageMagick - is a robust collection of tools and libraries to read,
write, and manipulate an image in many image formats.

Home Page: http://www.imagemagick.org/

Suse

Page: http://www.novell.com/products/linuxpackages/professional/imagemagick.html


Labels:

Collateral
Comment List
Related
Recommended