planzelle

Convert dir structure with text files to pdf using enscript

Mar 21st, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. # REMEMBER: We must be in the correct dir!
  3.  
  4. # script will iterate through active directory and convert
  5. # text files (php|py|js) to pdf - copying the dir structure
  6. # postscript files reside in ../ps/ (interim, ending .ps)
  7. # pdf reside in ../pdf/ (ending .pdf)
  8. # depending on the amount of files it may take some time...
  9.  
  10. # requirement enscript:
  11. if [ ! -x $(which enscript) ]; then
  12.     echo "enscript is missing (sudo apt-get install enscript) - aborting!";
  13.     exit 1;
  14. fi
  15.  
  16. # requirement ps2pdf:
  17. if [ ! - $(which ps2pdf) ]; then
  18.     echo "ps2pdf is missing (sudo apt-get install ghostscript) - aborting!";
  19.     exit 1;
  20. fi
  21.  
  22. # we look for .php|.py|.js files and convert them
  23. find . -type f \( -iname "*.php" -or -iname "*.js" -or -iname "*.py" \) -print | while read ORIGIN; do
  24.     echo "$ORIGIN";
  25.     BASE=${ORIGIN:1};
  26.     PS=../ps"$BASE".ps;
  27.     PDF=../pdf"$BASE".pdf; echo "$PDF";
  28.     if [[ ! -d $(dirname "$PS") ]]; then mkdir -p $(dirname "$PS");fi;
  29.     if [[ ! -d $(dirname "$PDF") ]]; then mkdir -p $(dirname "$PDF"); echo "$PDF";fi;
  30.     enscript -o "$PS" "$ORIGIN";
  31.     ps2pdf "$PS" "$PDF";
  32. done
  33. exit 0
Add Comment
Please, Sign In to add comment