You’re often faced with a delimma where you get a set of files from somewhere with the filenames not matching the contents. They may be chapters from a book where it would be good if the title matched the chapter name. We’re previously covered a post on A-PDF Rename, a software which can use the PDF Title metadata to batch rename a set of files. But for complex tasks like where the Title metadata has not been set for some files, A-PDF Rename fails. I’d been using Linux script to workaround this for months. Here’s my script to batch rename such files (may need to be tweaked for your file):
#!/bin/bash if [ "$1" == "" ] then direc="$PWD" else echo $1 direc="$1" fi for file in *pdf do chap="" name="" chap=`pdf2txt -p 1 "$file" | grep 'CHAPTER' -A3 | sed '2q;d' | sed -e 's/^[ \t]*//' | sed 's/[ \t]*$//'` if [ "$chap" == "" ] then name=`pdf2txt -p 1 "$file" 2>/dev/null | sed '3q;d' | sed -e 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed 's/ \+/ /g' | sed 's/://g' | sed 's/\*//g'` newname="$name.pdf" else name=`pdf2txt -p 1 "$file" | grep 'CHAPTER' -A3 | sed '4q;d' | sed -e 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed 's/ \+/ /g' | sed 's/://g' | sed 's/\*//g'` newname="$chap-$name.pdf" fi echo "$file => $newname" echo "move \"$file\" \"$newname\"" >> renfile.bat done
But if you’re a Windows user, don’t despair. Enter, A-PDF Preview and Rename, a software that can help you draw boxes around text that contains the name of the pdf that you would like, and recognizes it by OCR, and can even use the similiar location to rename multiple files simultaneously. Get it from here.
The steps to do this are included as screenshots below:
Step1: Draw the files into A-PDF Preview and Rename app:
Step 2: Click on a file, and select option “Select text and OCR”. Drag a box with the mouse around the text you want to select.
Step 3. Click on “OCR” option. You will be shown a preview of the new filename. If this is correct, choose the “Batch OCR” option to rename all files. Note that the program is not 100% accurate, and you may still need to manually correct the filenames in some cases. Still, it works great for a lot of files.