Commit | Line | Data |
---|---|---|
5a6f71ba P |
1 | #!/bin/bash |
2 | # gpdftk — interface graphique pour pdftk (manipulation de PDF) | |
3 | # Copyright ©2009-2010 Agence universitaire de la Francophonie | |
4 | # http://www.auf.org/ | |
5 | # Licence : GNU General Public License, version 3 | |
9458dba3 P |
6 | # Auteurs : Đoàn Mạnh Hà <doan.manh.ha@auf.org> |
7 | # Progfou <jean-christophe.andre@auf.org> | |
5a6f71ba | 8 | # Création : 2009-06-02 |
9458dba3 P |
9 | # Mise à jour : 2010-03-12 |
10 | PDFVIEWER="evince" | |
5a6f71ba P |
11 | FILEBROWSER="nautilus" |
12 | ||
13 | TEMPFILE=`tempfile` | |
14 | trap "rm -f \"$TEMPFILE\"" 0 1 2 3 15 | |
15 | ||
16 | ########################################################################### | |
17 | # jointure de fichiers PDF | |
18 | ########################################################################### | |
19 | ||
20 | operation_joindre() { | |
21 | zenity --file-selection --multiple > "$TEMPFILE" | |
22 | if [ $? != 0 ]; then return 1; fi | |
23 | OUT=`zenity --file-selection --filename="output.pdf" --save` | |
24 | if [ $? != 0 ]; then return 1; fi | |
25 | eval "pdftk `sed 's/^/"/;s/|/" "/g;s/$/"/' "$TEMPFILE"` cat output \"$OUT\"" | |
26 | $PDFVIEWER "$OUT" & | |
27 | return 0 | |
28 | } | |
29 | ||
30 | ########################################################################### | |
31 | # extraction de toutes les pages d'un fichier PDF | |
32 | ########################################################################### | |
33 | ||
34 | operation_extraire_toutes() { | |
35 | echo "Vous avez choisi 'extraire toutes les pages'." | |
9458dba3 | 36 | IN=`zenity --file-selection` |
5a6f71ba | 37 | if [ $? != 0 ]; then return 1; fi |
9458dba3 | 38 | DIR="$IN".tmp |
5a6f71ba P |
39 | mkdir "$DIR" |
40 | cd "$DIR" | |
9458dba3 | 41 | eval "pdftk \"$IN\" burst" |
5a6f71ba P |
42 | if [ $? != 0 ]; then |
43 | zenity --info --text="Erreur pendant l'extraction. Un problème dans les plages spécifiées peut-être ?" | |
44 | return 1 | |
45 | fi | |
46 | zenity --info --text="L'extraction est terminée. | |
47 | Elle a été effectuée dans le répertoire temporaire suivant : | |
48 | $DIR | |
49 | ||
50 | Merci d'effacer ce répertoire temporaire à la fermeture du navigateur de fichiers." | |
51 | $FILEBROWSER . | |
52 | return 0 | |
53 | } | |
54 | ||
55 | ########################################################################### | |
56 | # extraction de plages de pages d'un fichier PDF | |
57 | ########################################################################### | |
58 | ||
9458dba3 P |
59 | operation_selectionner_plage() { |
60 | echo "Vous avez choisi 'sélectionner une ou plusieurs plages de pages'." | |
61 | IN=`zenity --file-selection` | |
5a6f71ba | 62 | if [ $? != 0 ]; then return 1; fi |
9458dba3 | 63 | PLAGE=`zenity --entry --text="Pour sélectionner de la page 2 à 6, saisissez comme suit : 2-6"` |
5a6f71ba | 64 | if [ $? != 0 ]; then return 1; fi |
9458dba3 P |
65 | OUT="${IN%.pdf}-selection.pdf" |
66 | eval "pdftk \"$IN\" cat \"$PLAGE\" output \"$OUT\"" | |
5a6f71ba | 67 | if [ $? != 0 ]; then |
9458dba3 | 68 | zenity --info --text="Erreur pendant la sélection. Un problème dans les plages spécifiées peut-être ?" |
5a6f71ba P |
69 | return 1 |
70 | fi | |
9458dba3 P |
71 | zenity --info --text="La sélection est terminée. |
72 | Elle a été sauvegardée avec le nom de fichier suivant : | |
73 | $OUT" | |
74 | $PDFVIEWER "$OUT" & | |
5a6f71ba P |
75 | return 0 |
76 | } | |
77 | ||
78 | ########################################################################### | |
79 | # rotation de fichiers PDF | |
80 | ########################################################################### | |
81 | ||
82 | operation_rotation() { | |
9458dba3 P |
83 | echo "Vous avez choisi 'effectuer une rotation'." |
84 | IN=`zenity --file-selection` | |
5a6f71ba | 85 | if [ $? != 0 ]; then return 1; fi |
9458dba3 | 86 | ROTATION=`zenity --entry --text="Pour une rotation de 90°, 180° ou 270°, saisissez comme suit : 1-endE ou 1-endS ou 1-endW"` |
5a6f71ba | 87 | if [ $? != 0 ]; then return 1; fi |
9458dba3 P |
88 | OUT="${IN%.pdf}-rotation.pdf" |
89 | eval "pdftk \"$IN\" cat \"$ROTATION\" output \"$OUT\"" | |
5a6f71ba P |
90 | if [ $? != 0 ]; then |
91 | zenity --info --text="Erreur pendant la rotation. Un problème dans la saisie peut-être ?" | |
92 | return 1 | |
93 | fi | |
94 | zenity --info --text="La rotation est terminée. | |
9458dba3 P |
95 | Elle a été sauvegardée avec le nom de fichier suivant : |
96 | $OUT" | |
97 | $PDFVIEWER "$OUT" & | |
5a6f71ba P |
98 | return 0 |
99 | } | |
100 | ||
101 | ########################################################################### | |
102 | # boucle de gestion du menu principal | |
103 | ########################################################################### | |
104 | ||
105 | while true; do | |
106 | ||
107 | zenity --width 430 --height 230 --list --title "Traitement des PDF" \ | |
108 | --text "Choisissez l'opération souhaitée :" \ | |
109 | --column "" --column "Opération" --radiolist \ | |
110 | - "Joindre plusieurs fichiers PDF ensemble" \ | |
111 | - "Extraire toutes les pages d'un fichier PDF" \ | |
9458dba3 | 112 | - "Sélectionner une ou plusieurs plages de pages d'un fichier PDF" \ |
5a6f71ba P |
113 | - "Effectuer une rotation sur un fichier PDF" \ |
114 | > "$TEMPFILE" | |
115 | if [ $? = 1 ]; then exit 0; fi | |
116 | ||
117 | case "`cat "$TEMPFILE"`" in | |
118 | "Joindre"*) if operation_joindre; then exit 0; fi ;; | |
119 | "Extraire toutes"*) if operation_extraire_toutes; then exit 0; fi ;; | |
9458dba3 | 120 | *"plage"*) if operation_selectionner_plage; then exit 0; fi ;; |
5a6f71ba P |
121 | *"rotation"*) if operation_rotation; then exit 0; fi ;; |
122 | "") zenity --info --text "Vous devez choisir une opération." ;; | |
123 | *) echo "Erreur : cas non géré." ; exit 1 ;; | |
124 | esac | |
125 | ||
126 | done | |
127 | ||
128 | ########################################################################### | |
129 | # fin du programme | |
130 | ########################################################################### | |
131 | ||
132 | exit 0 |