I wrote a little shell function which creates a fixed-size PDF file (A4) from a character string using gs:
make_stamp() {
file=$1
string=$2
tmp=${file}-small.pdf
gs -o "$tmp" -sDEVICE=pdfwrite -g500x200 \
-c "/Helvetica findfont 12 scalefont setfont" \
-c "0 1 0 0 setcmykcolor" \
-c "0 5 moveto" \
-c "(${string}) show" \
-c "showpage"
gs -o "$file" -sDEVICE=pdfwrite -g5950x8420 \
-c "<</PageOffset [510 20]>> setpagedevice" \
-f "$tmp"
}
However, there are a few things that I would like to improve:
- when creating
$tmp, how do I set a solid background colour? - when creating
$tmp, is it possible to have the size auto-calculated to be tightly around the text, maybe with a fewptas padding? - is it possible to rewrite this function to only call
gsonce?
or
- is there another way to do this which doesn't use
gsdirectly? The stamp file must be textual, a rendered image is no good.
For anyone who is interested, I use the output of this function $stamp in a call to pdftk like this:
pdftk original.pdf stamp $stamp output stamped.pdf