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
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.
gs \
-o A4-stamp.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-c "<</PageOffset [280 790]>> setpagedevice" \
-f stamp-small.pdf
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
To add an image to a PDF one time only, simply paste the image into the document. Pasted images have the same characteristics as other stamp comments; each includes a pop-up note and editable properties. Open the Stamps Palette by doing one of the following: Choose Tools > Stamp > Stamps Palette.
There seem to be some issues related to:
In short, without going into the details of the problems, you can use
convert image.png -size 640x562 xc:white +swap -compose over -composite image.jpg
- this removes png transparency to white (as background) and converts image to jpg (note the -size, this is the same as the image you added in this post, but should be stated to be the correct one for your stamp)img2pdf image.jpg -o image.pdf
- properly add jpg image to pdfgs -o A4-image.pdf -sDEVICE=pdfwrite -g5950x8420 -c "<</PageOffset [100 500]>> setpagedevice" -f image.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With