The following script makes use of a temporary file "data.txt" to which something is appended before reusing it. (Actually I simply add some metadata to a PDF)
#!/bin/bash
PDFTK="/app/bin/pdftk"
#PDFTK="pdftk"
$PDFTK $1.pdf dump_data output data.txt
cat >> data.txt << EOF
InfoBegin
InfoKey: Myproperty
InfoValue: Myvalue
EOF
$PDFTK $1.pdf update_info data.txt output $1-$2.pdf
Both dump_data and update_info can write/read from stdout (see man pdftk)
bash-gurus: How can I rewrite the code such that no file is created ?
pdftk-gurus: Is there a better way to add a key/value pair?
Thanks, Bastl.
pdftk
writes to standard output by default, then my updated answer may work. It's not pretty, and honestly, I would probably go with using a temporary file. – Kusalananda Sep 30 '17 at 19:55