dotfiles/config/nix/scripts/pdfrename
Geoffrey Frogeye 1f61ceb395
nix: Migrate scripts
They're a bit slower to start :(.
Hopefully this is something that flakes will help with,
otherwise I'll find another way.
2023-11-26 21:04:58 +01:00

52 lines
1.2 KiB
Plaintext
Executable file

#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash pdftk coreutils
# Change the title of a PDF file
if [[ -z "$1" || -z "$2" ]]; then
echo "Usage: $0 FILE TITLE [CREATOR [PRODUCER]]"
echo
echo "Arguments:"
echo " FILE Path to the PDF document"
echo " TITLE Content of the Title tag"
echo " CREATOR Content of the Creator tag"
echo " PRODUCER Title to give"
exit 1
fi
file="$1"
title="$2"
creator="$3"
producer="$4"
if [ ! -f "$1" ]; then
echo "No such file or directory: $1" >> /dev/stderr
exit 2
fi
instructions=$(mktemp)
echo "InfoBegin" >> "$instructions"
echo "InfoKey: Title" >> "$instructions"
echo "InfoValue: $title" >> "$instructions"
if [ -n "$creator" ]; then
echo "InfoBegin" >> "$instructions"
echo "InfoKey: Creator" >> "$instructions"
echo "InfoValue: $creator" >> "$instructions"
fi
if [ -n "$producer" ]; then
echo "InfoBegin" >> "$instructions"
echo "InfoKey: Producer" >> "$instructions"
echo "InfoValue: $producer" >> "$instructions"
fi
copy=$(mktemp)
cp "$file" "$copy"
pdftk "$copy" update_info "$instructions" output "$file"
rm "$instructions" "$copy"