#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/pdf-meta pdf-length-many () { local fs=($@) local ext local pages local chars local total_pages=0 local total_chars=0 for f in $fs; do if [[ ! -f $f ]]; then no-file-msg $f return 1 else ext=${f:e} case $ext in (pdf) chars=$(pdftotext $f - 2> /dev/null | wc -c) pages=$(pdf-number-of-pages $f) total_pages=$(( $total_pages + $pages )) total_chars=$(( $total_chars + $chars )) echo "${(l:5:: :)pages} ${(l:6:: :)chars} $f" ;; (*) print-ext-error-msg $ext return 1 ;; esac fi done if [[ ${#fs} > 1 ]]; then echo "${(l:5:: :)total_pages} ${(l:6:: :)total_chars} total" fi } pdf-length-2 () { local f=$1 pdftk $f dump_data | awk '/NumberOfPages/{ print $2 }' } pdf-length () { local f=$1 pdfinfo $f | awk '/Pages:/{ print $2 }' }