#!/bin/bash #Company: PowerCraft Technology #Author: Copyright Jelle de Jong #Note: Please send me an email if you enhanced this script #Version: 0.0.1 #Date: 15-01-2007 #System: Ubuntu/Debian GNU/Linux #Information: man pdftk, man test #Category Thunar scripts #Name: Toolkit PDF #Description: Encrypt and merge PDF files #Command: xfce4-terminal --disable-server --hide-toolbars --execute /usr/share/pct-thunar-scripts/scripts/file-pdftoolkit %F #Patterns: *.pdf; *.PDF; #Other Files: True # Did the script work for you? # Yes # Yes, but with some errors # Yes, but I had to change some things # Not at all # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=${0##*/} NAME=$"Toolkit PDF" DESCRIPTION=$"Encrypt and merge PDF files" cecho() { case "$1" in "black") echo -ne "\E[30m" ;; "red") echo -ne "\E[31m" ;; "green") echo -ne "\E[32m" ;; "yellow") echo -ne "\E[33m" ;; "blue") echo -ne "\E[34m" ;; "magenta") echo -ne "\E[35m" ;; "cyan") echo -ne "\E[36m" ;; *) echo -ne "\E[30m" exit ;; esac echo "$2" "$3" tput sgr0 } cecho "green" $"program:" echo "$0" cecho "green" $"description:" echo "$DESCRIPTION" cecho "magenta" $"processing file(s): " for I in "$@" do filename="${I##*/}" cecho "blue" "$filename" done echo -n $"are you sure you want to continue [Y/n]? " read input if [ "$input" = "n" ] then exit 0 fi #whereis pdftk if [ ! -e /usr/bin/pdftk ] then cecho "red" $"pdf toolkit not found, installing now" sudo apt-get install pdftk fi encrypt_pdf() { if [ "$filetype" = "PDF document" ] then cecho "magenta" $"encrypt pdf file using 128-bit strength" cecho "green" $"enter the encryption password for the pdf file(s)" read -p $"password: " -s pwd if [ ! -d encrypted ] then mkdir encrypted fi pdftk "$1" input_pw $pwd output encrypted/"$filename" user_pw "$pwd" fi } combine_pdf() { if [ "$filetype" = "PDF document" ] then cecho "magenta" $"combine pdf file" if [ ! -d combined ] then mkdir combined fi if [ -f "$1" ] then [[ "$1" = *.pdf ]] && query+=("$1") pdftk "${query[@]}" cat output combined/combined.pdf fi fi } cecho "green" $"choose a option" cecho "blue" $"[1] encrypt pdf file(s)" cecho "blue" $"[2] merge pdf file(s)" read option for I in "$@" do filename="${I##*/}" cecho "green" $"starting with:" cecho "blue" "$filename" filetype=$(file -b "$I" | cut -f 1 -d ",") cecho "green" $"file type is:" echo "$filetype" if [ "$option" = "1" ] then encrypt_pdf "$I" fi if [ "$option" = "2" ] then combine_pdf "$I" fi cecho "green" $"completed with:" cecho "blue" "$filename" cecho "blue" "---------------" done echo $"done, closing after 25 seconds" sleep 25 exit 0