A quick script to rename a pdf file based on the 1st line on the 1st page (Generally a title of some sort). We all get pdfs occassionally that have some weird name like css223.pdf.. this will fix that, batch, in the PWD.
#!/bin/bash
#——————————————————
# Written by Stephen Coetzee, 22/06/2009
# DESC: A simple script that’ll rename all pdf files in pwd according to the first line of text in that pdf (usually a title of some sort)
# USAGE: ./pdfname
#——————————————————for n in *.pdf ; do
pdftotext -l 1 “${n}”
name=”$(head -n1 “${n%.*}”.txt | tr -d ‘ ‘ | tr -d “[:punct:]“)”
echo “Renaming “${n}” to “${name}”.pdf”
mv “${n}” “${name}”.pdf
rm -f *.txt
done
#1 by Jinny on June 30, 2009 - 2:11 pm
Not sure that this is true:), but thanks for a post.
#2 by stephen on June 30, 2009 - 2:20 pm
Well it’s worked for me so far..