So here is the situation, I have a folder that contains all the images named sequentially. The images then need to be converted to PDFs and then combined into one file. Additionally I want a grayscale version and a colour version. As usual, the easiest way to do this is with a script in linux. If you haven't got them already, you will need to run the following commands to install packages for this to work.
sudo apt-get install imagemagick
sudo apt-get install pdftk
Imagemagick is an awesome tool for processing images, particularly when processing batches of them, and Pdftk is a tool kit that allows you to rearrange, remove, and add pages to to pdf files. With these two tools the following script does the job nicely.
#!/bin/bash
mkdir Col
mkdir BW
rm -rf ./Col/*
rm -rf ./BW/*
ls *.png | sed -e "s/.png$//" | xargs -r -I FILE \
mkdir Col
mkdir BW
rm -rf ./Col/*
rm -rf ./BW/*
ls *.png | sed -e "s/.png$//" | xargs -r -I FILE \
convert FILE.png -density 300x300 -compress jpeg \
-quality 60 ./Col/FILE.pdf
ls *.png | sed -e "s/.png$//" | xargs -r -I FILE \
convert FILE.png -colorspace gray -density 300x300 \
-compress jpeg -quality 60 ./BW/FILE.pdf
pdftk ./BW/*.pdf cat output BW.pdf
pdftk ./Col/*.pdf cat output Col.pdf
rm -rf ./Col/*
rm -rf ./BW/*
rmdir ./Col
rmdir ./BW
pdftk ./BW/*.pdf cat output BW.pdf
pdftk ./Col/*.pdf cat output Col.pdf
rm -rf ./Col/*
rm -rf ./BW/*
rmdir ./Col
rmdir ./BW
Next pdftk is used to combine the PDF's that were just created into one file. The order of the pages in the PDF is based on the alphabetical order of the input files.
The intermediary files and folders are then deleted. Job done, and I could leave the computer unattended for most of the time as well.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.