Guest User

Untitled

a guest
Nov 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Petit script qui utilise pdfinfo pour extraire de manière récursive des infos sur des PDFs dans un csv.
  4. # Il est nécessaire que pdfinfo soit disponible (e.g : brew install xpdf sous OS X).
  5. # [usage]: ./pdf_folders_to_csv.sh /path/to/folder/of/pdfs [csv_file_name]
  6.  
  7. [[ -z "$2" ]] && CSV_FILE="pdf_folders_to_csv.csv" || CSV_FILE="$2"
  8. echo "Filename;Author;Producer;ModDate;Pages;Format" > "${CSV_FILE}";
  9.  
  10. while read -r line
  11. do
  12. NOMBRE_PAGE=$(pdfinfo $line | grep Pages | awk '{print $2}')
  13. FORMAT=$(pdfinfo $line | grep "Page size" | cut -d ':' -f2 | sed 's/^ *//g')
  14. AUTHOR=$(pdfinfo $line | grep "Author" | cut -d ':' -f2 | sed 's/^ *//g')
  15. PRODUCER=$(pdfinfo $line | grep "Producer" | cut -d ':' -f2 | sed 's/^ *//g')
  16. MODDATE=$(pdfinfo $line | grep "ModDate" | cut -d ':' -f2 | sed 's/^ *//g')
  17. #JAVASCRIPT=$(pdfinfo $line | grep "JavaScript" | cut -d ':' -f2 | sed 's/^ *//g')
  18. #DOSSIER=$(dirname $line | tr -d '.' | sed 's/\//\ /g')
  19. FICHIER=$(basename $line)
  20. echo "${FICHIER};${AUTHOR};${PRODUCER};${MODDATE};${NOMBRE_PAGE};${FORMAT}" >> "${CSV_FILE}"
  21. done <<< "$(find $1 -type f -iname '*.pdf')"
  22.  
  23. #cat $CSV_FILE
  24. csvlook -d ";" pdf_folders_to_csv.csv
Add Comment
Please, Sign In to add comment