Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

  1. when creating $tmp, how do I set a solid background colour?
  2. when creating $tmp, is it possible to have the size auto-calculated to be tightly around the text, maybe with a few pt as padding?
  3. is it possible to rewrite this function to only call gs once?

or

  • is there another way to do this which doesn't use gs directly? 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
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.