Skip to main content
Participant
November 7, 2022
Question

Wrong Stamp what ever AP value i use

  • November 7, 2022
  • 2 replies
  • 609 views

Hi, 

 

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

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
November 7, 2022

How did you get that AP value?

Thom Parker
Community Expert
Community Expert
November 7, 2022

Good point.  Here's a video on how to discover the stamp name.

https://www.pdfscripting.com/public/images/Video/FindingStampName.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
November 7, 2022

While VBA is case insensitive, JavaScript is case sensitive, so try changing "props.ap" to "props.AP". 

 

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.

Next, I'm not convinced the VBA "props" object will translate properly into the JavaScript "props" object.  I typically write folder level functions to perform any actions that involve objects, then call those functions from the VBA to avoid any issues with translations across the VBA/JS boundary. 

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often