Created
December 27, 2011 12:17
-
-
Save hugomaiavieira/1523453 to your computer and use it in GitHub Desktop.
Script to convert all kind of files in a directory to pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# a2pdf: Script to convert all kind of files in a directory to pdf | |
# | |
# Author: Hugo Maia Vieira <[email protected]> | |
# | |
# Dependencies: tree, cedilla, ps2pdf | |
# | |
# TODO: Separar em funções "concatenar", "converter" e "concatenar e converter" | |
# para poderem ser chamadas separadamente. | |
# | |
MENSAGEM_USO=" | |
$(basename "$0") - Script que buscar recursivamente em um diretório por todos os | |
tipos de arquivo e os converte em um único arquivo .pdf | |
USO: $(basename "$0") (DIR OUTPUT) | |
DIR Arquivo ou diretório raiz onde será feita a busca por arquivos a | |
serem impressos. | |
OUTPUT Nome do arquivo de saída. Para nomes com espaço, usar aspas. | |
" | |
if [ ! -e $1 ] || [ -z $2 ]; then | |
echo "$MENSAGEM_USO" | |
exit 1 | |
fi | |
DIR=$1 | |
OUTPUT=$2 | |
TMP_DIR='/tmp/a2pdf' | |
[ -d $TMP_DIR ] || mkdir $TMP_DIR | |
for i in $(tree -if $1) | |
do | |
if [ -f $i ]; then | |
ps_name=$(echo $i | sed 's/\//_/g') | |
ps_file="$TMP_DIR/$ps_name.ps" | |
cedilla -w -h "$i",,%p $i $ps_file | |
cd $TMP_DIR | |
ps2pdf $ps_file | |
cd - | |
fi | |
done | |
# Concatenate all .pdf's in one | |
gs -q \ | |
-dNOPAUSE \ | |
-dBATCH \ | |
-sDEVICE=pdfwrite \ | |
-sOutputFile=$TMP_DIR/$OUTPUT.pdf \ | |
$TMP_DIR/*.pdf | |
mv $TMP_DIR/$OUTPUT.pdf . | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment