Skip to content

Instantly share code, notes, and snippets.

@seikichi
Created March 1, 2011 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seikichi/849716 to your computer and use it in GitHub Desktop.
Save seikichi/849716 to your computer and use it in GitHub Desktop.
自炊したpdfから最初と最後の3ページの画像を確認してバーコードを探しファイル名を"<ISBN13>.pdf" に変換.
#!/bin/bash
rm -f .image*
CHECK=3
for file in *.pdf; do
pages=$(pdfinfo "$file" | grep -E '^Pages' | sed -e 's/^Pages:\s*//') &&
pdfimages -j -l $CHECK "$file" .image_h &&
pdfimages -j -f $(expr $pages - $CHECK) "$file" .image_t &&
title="$(zbarimg -q .image* | uniq | grep -E '^EAN-13:978' | sed -e 's/^EAN-13://').pdf" &&
[ $title != ".pdf" ] &&
mv "$file" $title ||
echo "Error in $file"
rm -f .image*
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment