问题
I'm tryin to add a text comment (not a note) to a pdf file. I create a date.ps file with contains the text comment : %! /Arial findfont 30 scalefont setfont newpath 10 720 moveto (PAID on 5.1.2013) show showpage
and I launch the shell command with $i=name of the pdf file to tag: gs -q -dNOPAUSE -dSAFER -dBATCH -sOutputFile=$RFP/$DOMAINE/$NEWNAME -sDEVICE=pdfwrite -sPAPERSIZE=a4 date.ps $i
This works, but it create a new 1st page empty with the text "PAID on 5.1.2013" alone.
I do not find the trick to overlay the text on the 1st page of the original pdf.
Can you help me pls
回答1:
Because your PostScript executed a showpage it ejects the first page after marking it, so the remaining content is therefore on the 2nd and subsequent pages. If you don;t execute showpage then the marks you make will be on the first page, and the first PDF page will be drawn 'on top' of it.
More complex code can use BeginPage and EndPage to draw over and under the page contents, and to do so on specified pages, among other things.
[added later]
Try this:
%!
<<
/EndPage
{
0 eq
{
0 eq
{
/Arialabold findfont 22 scalefont setfont newpath 250 820 moveto 1 0 0 setrgbcolor (PAYE PAR CCP LE $DATEPMT) show
} if
true
}
{
pop false
} ifelse
} >> setpagedevice
Works for me.
回答2:
You can do this directly to the PDF using the free cpdf command line tools:
For example,
cpdf -add-text "PAID on 5.1.2013" -topleft 100 -font "Helvetica" -font-size 30 in.pdf -o out.pdf
来源:https://stackoverflow.com/questions/18769314/add-text-on-1st-page-of-a-pdf-file