Se você possui um grande número de PDFs em uma estrutura de pastas e uma instalação TeX, esse script coloca todos os PDFs recursivamente em um arquivo grande:
#!/bin/bash
#
# pdfdir OUTPUT_FILE
#
# produces one big PDF file of all PDF files in .
#
if [ $# -ne 1 ] || [ -z "$1" ]; then
echo "Syntax: pdfdir OUTPUT_FILE"
exit 1
fi
FILE="$(echo "$1"|sed -e 's/\.\(pdf\|tex\)$//')"
for F in "$FILE" "$FILE.tex" "$FILE.pdf" "$FILE.aux" "$FILE.log" ; do
if [ -e "$F" ]; then
echo "$F exists already."
exit 2
fi
done
cat >"$FILE.tex" <<EOF
\documentclass{article}%
\usepackage{pdfpages}%
\usepackage{grffile}%
\listfiles%
\begin{document}%
%\tableofcontents%
EOF
# helper functions
exist_pdf_files () {
[ $(find -L "$1" -name \*.pdf -o -name \*.PDF -type f 2>/dev/null|wc -l) -eq 0 ] && return 1
return 0
}
list_directories () {
find -L "$1" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort
}
list_pdf_files () {
# version with " around filenames:
#find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 2>/dev/null | sort | \
# sed -e 's/^/\\includepdf[pages=-]{"/; s/$/"}%/'
# version without " around filenames:
find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 2>/dev/null | sort | \
sed -e 's/^/\\includepdf[pages=-]{/; s/$/}%/'
}
tex_headline () {
echo "$1" | sed -e 's/_/\\_/g'
}
# current folder (lefel 0):
list_pdf_files . >>"$FILE.tex"
# Bearbeite Ebene 1:
list_directories . | while read -r DIR1; do
# Are there PDFs in folders below that level?
exist_pdf_files "$DIR1" || continue
# Yes ...
tex_headline "\section{${DIR1##*/}}%"
# those:
list_pdf_files "$DIR1"
# Level 2:
list_directories "$DIR1" | while read -r DIR2; do
exist_pdf_files "$DIR2" || continue
tex_headline "\subsection{${DIR2##*/}}%"
list_pdf_files "$DIR2"
# Level 3:
list_directories "$DIR2" | while read -r DIR3; do
exist_pdf_files "$DIR3" || continue
tex_headline "\subsubsection{${DIR3##*/}}%"
list_pdf_files "$DIR3"
# Level 4:
list_directories "$DIR3" | while read -r DIR4; do
exist_pdf_files "$DIR4" || continue
tex_headline "\paragraph{${DIR4##*/}}%"
list_pdf_files "$DIR4"
# Level 5:
list_directories "$DIR4" | while read -r DIR5; do
exist_pdf_files "$DIR5" || continue
tex_headline "\subparagraph{${DIR5##*/}}%"
list_pdf_files "$DIR5"
done
done
done
done
done >>"$FILE.tex"
echo "\end{document}%" >>"$FILE.tex"
echo "Sourcecode to PDF directly [J/n]"
read -r ANSWER
case "$ANSWER" in
[JjYy]) ;;
*) exit 0 ;;
esac
pdflatex "$FILE"
[ $? -eq 0 ] && rm -f "$FILE.aux" "$FILE.log" "$FILE.tex"
Não escrevi esse código, obtive-o de uma discussão aqui:
http://www.listserv.dfn.de/cgi-bin/wa?A2=ind1201&L=tex-dl&T=0&P=10771
É muito útil. Traduzi alguns comentários em alemão para o inglês.
Atenciosamente, Alexander