ref: 3b8c26ceaf773a1dcb3b3abf1be53895de7b9911
dir: /bin/pdfid/
#!/bin/rc
# set the pdf ID to a given ID
# $1 is pdf file, $2 is the checksum
# assume ramfs in /tmp
rfork en
# get size of the file
size=`{du -n $1}
size=$size(1)
todump=`{echo $size - 160 | hoc}
# 160 characters should make sure that we actually have the ID, and that we skipped the binary part
# split file $1 into parts
dd -if $1 -bs 1 -count $todump -quiet 1 > /tmp/pdf_part1
dd -if $1 -bs 1 -count 160 -iseek $todump -quiet 1 > /tmp/pdf_part2
# replace ID
sed 's:^/ID \[<[A-Z0-9]+><[A-Z0-9]+>\]$:/ID [<'^$2^'><'^$2^'>]:g' /tmp/pdf_part2 > /tmp/pdf_part2_edited
# recombine file to stdout, and cleanup
cat /tmp/pdf_part1 /tmp/pdf_part2_edited
rm /tmp/pdf_part1 /tmp/pdf_part2 /tmp/pdf_part2_edited