I am currently writing an application in which wone of the processes is to stamp an existing 1-page pdf-document with an image provided by the user. The stamp needs to be scaled and position correctly onto the pdf.
I've successfully followed the incstructions in Kurt Pfeifle's answer to Stamp PDF file with control for position of stamp file .
In the answer, Kurt
- Creates a stamp on the fly using ghostscript.
- Creates an empty A4-sized-pdf, with the stamp position in.
- He then merges the newly created pdf, with the original pdf using
pdftk
As I said, this all works great. However, if I do the same process with my own image-file(converted to pdf), something goes wrong in the second step with the sizing in the second step. The sizing in the command seems to be ignored, and instead, the pdf gets the same size as the image. Se output below for a comparison of original command with original stamp as pdf and my modified command using a converted image.
Original working command:
gs \
-o A4-stamp.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-c "<</PageOffset [280 790]>> setpagedevice" \
-f stamp-small.pdf
Modified command with image
gs \
-o A4-image.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-c "<</PageOffset [280 790]>> setpagedevice" \
-f image.pdf
As can be seen, the size and ratio is all wrong, and should match the original.
The original stamp-small.pdf
(from original answer) can be generated like this:
gs \
-o stamp-small.pdf \
-sDEVICE=pdfwrite \
-g3200x500 \
-c "/Helvetica-Bold findfont 36 scalefont setfont" \
-c "0 .8 0 0 setcmykcolor" \
-c "12 12 moveto" \
-c "(This is my stamp) show" \
-c "showpage"
The image I used in the command is the following, but the same thing happens with any image I have tried, after converting the image to pdf:
convert image.png image.pdf