• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Wrong Stamp what ever AP value i use

New Here ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

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?

 

marianne26701311uy5t_0-1667818681173.png

 

 

 

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

 

TOPICS
Acrobat SDK and JavaScript

Views

24

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

How did you get that AP value?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines