For people that do not want to install a texlive distribution, you may prefer cpdf as explained here. However since cpdf has a strange license for commercial use, I tried to find an alternative. Here is one (you need to install enscript, ps2pdf and (pdftk or qpdf)).
The idea is just to use enscript to create a .ps from a text, then you convert this .ps into a .pdf using ps2pdf, and then you stack it on top of the original pdf with pdftk or qpdf...).
pdtfk version:
echo "I will be stamped on top of the page" | enscript -B -f Courier-Bold16 -o- | ps2pdf - | pdftk input.pdf stamp - output output.pdf
qpdf version:
If you want the text to repeat on all pages:
tmpfile=$(mktemp) && echo "I will be stamped on top of the page" | enscript -B -f Courier-Bold16 -o- | ps2pdf - "$tmpfile" && qpdf out_merge.pdf --overlay "$tmpfile" --repeat=1-z -- out_oneline.pdf
if you just want to put it on the first page:
tmpfile=$(mktemp) && echo "I will be stamped on top of the page" | enscript -B -f Courier-Bold16 -o- | ps2pdf - "$tmpfile" && qpdf out_merge.pdf --overlay "$tmpfile" -- out_oneline.pdf
See the documentation for more options.
NB: mktemp is just used to create a temporary file to provide a one-liner solution, since qpdf does not accept input from stdin
Unfortunately, I'm not sure to know how to set the position of the text, for not it's always on top left in a4 pages...