Newer Older
76 lines | 2.42kb
ajout scripts utilisés
Sébastien authored on 2023-04-24
1
#!/bin/bash
2

            
3
couleur_default="Niveaux de gris"
4
quantite_default=10
5
warning_qty=250
6

            
7
declare -A _type=([Couleur]=CMYK [$couleur_default]=Gray)
8
declare -A _ecoprint=([Non]=Off [Oui]=On)
9
declare -A _format=([A4]=PF500B [A3]=PF500A)
10

            
11
get_size () {
12
	eval $(pdfinfo "$f" | awk '/^Page size:/{if ($6 == "pts") printf("mm_x=%d;mm_y=%d", $3*0.352778, $5*0.352778)}')
13
}
14
set -x
15
for f in "$@"; do
16
	file_type=$(file -bn "$f")
17
	if [[ $file_type =~ ^(Microsoft Word|OpenDocument Text) ]]; then
18
            libreoffice --headless --convert-to pdf "/dev/shm/${f##*/}.pdf" "$f"
19
	    f="/dev/shm/${f##*/}.pdf"
20
	fi
21
	file "$f" | grep -q ': PDF document, version' || continue
22
	sides=$(pdfinfo "$f" | awk '/^Page size:/{print ($3 > $5) ? "short" : "long"}')
23
	get_size
24
	while IFS='|' read type format ecoprint qty massicote <<< "$(yad --title "${f##*/}" --form \
25
		                                        --field='Type:CB' 'Couleur!^Niveaux de gris' \
26
		                                        --field='Format:CB' 'A3!^A4' \
27
							--field='EcoPrint:CB' 'Non!^Oui' \
28
							--field='Quantité:NUM' '1!1..500!1' \
29
							--field='Massicote-moi ça:CHK' 'FALSE' \
30
							--field="\n\nStatut imprimante:\n$(/usr/local/bin/printer status):LBL")"; do
31
		test -z "${qty}${type}" && exit
32
		if test ${qty:-10} -gt $warning_qty; then
33
			zenity --warning --text="Attention plus de $warning_qty impressions"
34
			continue
35
		fi
36
		if [[ ! "${f##*/}" =~ ^massicotable- && "$massicote" =~ ^TRUE ]]; then
37
			/usr/local/bin/massicot "$f"
38
			f="${f%/*}/massicotable-${f##*/}"
39
			sides="short"
40
			get_size
41
		fi
42
		if test $format = A3; then
43
			gs -o "/dev/shm/A3-${f##*/}" \
44
				-sDEVICE=pdfwrite \
45
				-sPAPERSIZE=a3 \
46
				-dFIXEDMEDIA \
47
				-dPDFFitPage \
48
				-dCompatibilityLevel=1.5 \
49
				"$f"
50
			f="/dev/shm/A3-${f##*/}"
51
		elif ! test "${mm_x}x${mm_y}" = "210x297" -o "${mm_x}x${mm_y}" = "297x210"; then
52
			gs -o "/dev/shm/A4-${f##*/}" \
53
				-sDEVICE=pdfwrite \
54
				-sPAPERSIZE=a4 \
55
				-dFIXEDMEDIA \
56
				-dPDFFitPage \
57
				-dCompatibilityLevel=1.5 \
58
				"$f"
59
			f="/dev/shm/A4-${f##*/}"
60
		fi
61
		lp -o InputSlot=${_format[$format]} \
62
		   -o sides=two-sided-$sides-edge \
63
		   -o ColorModel=${_type[${type}]} \
64
		   -o KCEcoprint=${_ecoprint[${ecoprint}]} \
65
		   -o KCCollate1=On \
66
		   -n ${qty} \
67
		   "$f"
68
		if test $format = A3; then
69
			rm -f "$f"
70
		fi
71
		if [[ $file_type =~ ^(Microsoft Word|OpenDocument Text) ]]; then
72
			rm -f "$f"
73
		fi
74
		break
75
	done
76
done