Create a gist now

Instantly share code, notes, and snippets.

#!/bin/bash
# Converte uma lista de imagens em 1 pdf único
# Criado Otávio Sampaio (osampaio at riopro dot com dot br)
# para a Riopro, Gestão Inteligente
# http://riopro.com.br
# Depende do imagemagick e do pdftk instalados
# testado no Ubuntu 9.10
# Script to convert images (like jpeg and png) to a single pdf
# Created by Otávio Sampaio (osampaio at riopro dot com dot br)
# Riopro, Gestão Inteligente
# http://riopro.com.br
# this script depends on imagemagick and pdftk installed.
# tested in a Ubuntu 9.10.
if [ "$1" == "" ]; then
USE_HELP="true"
fi
if [ "$1" == "--help" ]; then
USE_HELP="true"
fi
if [ "$USE_HELP" == "true" ]; then
echo "========================================================="
echo "Modo de usar:"
echo "convtopdf.sh DIRETORIO_DE_DESTINO LISTA_DE_IMAGENS"
echo "Exemplo:"
echo "convtopdf.sh ~/Desktop/ ~/*.jpg"
echo "ou"
echo "convtopdf.sh ~/ ~/arquivo1.jpg ~/arquivo2.jpg"
echo "Você precisa instalar o imagemagick e o pdftk"
echo "$ sudo aptitude install imagemagick pdftk"
echo "========================================================="
echo "========================================================="
echo "Using it:"
echo "convtopdf.sh DESTINATION_PATH IMAGES_LIST_OR_PATH"
echo "Example:"
echo "convtopdf.sh ~/Desktop/ ~/*.jpg"
echo "or"
echo "convtopdf.sh ~/ ~/file1.jpg ~/file2.jpg"
echo "This script depends on imagemagick and pdftk"
echo "$ sudo aptitude install imagemagick pdftk"
echo "========================================================="
exit 0;
fi
if [ "$1" != "" ]; then
TO_DIR="$1"
fi
FILES=("$@")
OUTPUT="output.pdf"
PARAMS_COUNT=${#FILES[@]}
MYPDFVAR=""
for (( i=1;i<$#;i++ )); do
convert ${FILES[${i}]} "${FILES[${i}]}.pdf"
echo "converted: ${FILES[${i}]} to ${FILES[${i}]}.pdf"
MYPDFVAR="$MYPDFVAR ${FILES[${i}]}.pdf"
done
echo "join $MYPDFVAR"
pdftk $MYPDFVAR output "$TO_DIR$OUTPUT.xxx"
echo "created $TO_DIR$OUTPUT.xxx"
for (( i=1;i<$#;i++ )); do
rm "${FILES[${i}]}.pdf"
echo "removing ${FILES[${i}]}.pdf"
done
mv "$TO_DIR$OUTPUT.xxx" "$TO_DIR$OUTPUT"
echo "Finished. Take a look at: $TO_DIR$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment