aboutsummaryrefslogtreecommitdiff
path: root/imgs2pdf.sh
blob: f0bad2c08d2dd5c8e92ecba481c30d26e0dee6f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

ext=$1
suffix=$2
out=$3

if [ -z "$suffix" ] ; then
    echo "Merge multiples images into a single pdf"
    echo "img2pdf (png,jpg,tiff,...) (suffix) [output]"
    echo ""
    echo "Ex :"
    echo "img2pdf jpg photo_book vacances_2017.pdf"
    exit
fi

if [ -z "$out" ] ; then
    out=$suffix.pdf
fi


echo "Prise en compte de " $(ls -v | egrep "^$suffix" | egrep "\.$ext\$")

while : ; do
  read -p "Continue (y/n)?" choice
  case "$choice" in 
    y|Y ) break;;
    n|N ) exit;;
    * ) echo "Invalid input";;
  esac
done



echo "$suffix"

for img in $(ls -v | egrep "^$suffix" | egrep "\.$ext\$") ; do
    echo Traitement de "$img"
    img2pdf --output "${img//$ext/pdf}" "$img"
done

if [ -e "$out" ] ; then
    echo "Gestion backup"
    set -x
    rm "$out"
    set +x
fi

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$out" `ls -v | egrep \.pdf$`

for img in *."$ext" ; do
    rm "${img//$ext/pdf}"
done