I found a piece of code on the internet, I'm trying to add a custom stamp on pdf with VBA.
It's working, I mean almost. Changing the property for Rect,Contents,Author or Name I can see the effect on my pdf. The only thing is, it always uses the Draft Stamp, nothing else whatever i pass in the AP property.
Any idea what i'm doing wrong?
Dim gApp As Acrobat.CAcroApp Dim gPDDoc As Acrobat.CAcroPDDoc Dim jso As Object Dim stampRect(3) As Integer Dim pageRect As Object Dim annot As Object Dim props As Object Dim page As Object Set gApp = CreateObject("AcroExch.App") Set gPDDoc = CreateObject("AcroExch.PDDoc") If gPDDoc.Open("whatever.pdf") Then Set jso = gPDDoc.GetJSObject Set page = gPDDoc.AcquirePage(0) Set pageRect = page.GetSize stampRect(0) = 100 stampRect(1) = 500 stampRect(2) = 400 stampRect(3) = 500 Set annot = jso.AddAnnot Set props = annot.getprops props.Type = "Stamp" annot.setProps props Set props = annot.getprops props.ap = "Test2" props.page = 0 props.rect = stampRect annot.setProps props End If
However, there are also few possible issues with the way the code is being run. I don't know if any of these are important, but they are worth checing out.
First of course, is that you must have a stamp named "Test2" installed.
Finally, the ordering of the code is not ideal. The annotation should be created will all relavant props passed into the "addAnnot" function. Changing props later, especially the "AP" value can be problematic, because the real stamp image is stored in an undocumented property. Once set, it has to be destroyed before a new image can be created. Just changing the AP value doesn't do it alone.
How did you get that AP value?
Good point. Here's a video on how to discover the stamp name.