VBA to Adobe Javascript (Format to date field) (1 Viewer)

mdnuts

Registered User.
Local time
Today, 07:34
Joined
May 28, 2014
Messages
120
After printing to PDF, I have vba creating a PDF form field. What I'm needing to do (and can't find) is how to set the format of that PDF form field to Date format?

I've found this in adobe's DC JS VBA bridge docs that Field SetAction has a ctrigger of "format" but they do not show how to handle that. Has anyone done this before?
 

neuroman9999

Member
Local time
Today, 06:34
Joined
Aug 17, 2020
Messages
836
well, let us see here. how exactly are you touching the PDF document if you are trying to manipulate it with VBA code? the last time I checked, there was actually a lib in VBA that could manipulate PDF documents. but I don't think it comes with office by default. but you say that you have found the resource in the "'bridge"" docs from Adobe? it probably depends on if the setAction method that you speak of is actually something found inside VBA or not. Is it? and if so, what lib does it come from?

by the way, I wonder if Colin welcomes me back....?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 28, 2001
Messages
19,035
Just for clarification: Did you install a full-function copy of Adobe in order to be able to create your own PDF documents from scratch? And also to be able to edit them from an Adobe-based GUI rather than through Office?

Or is this some special product from Adobe that allows you to use Javascript as a document source for your .PDF creations?
 

mdnuts

Registered User.
Local time
Today, 07:34
Joined
May 28, 2014
Messages
120
well what I've got is the following. I have some code above this that sets print ranges and declares the array to print. After creating the PDF the VBA add's in two date fields and two signature fields. The desire is to add in the action trigger on when a signature box is signed - the corresponding date field fills in. I've gotten some advice that said to use folder level scripts (using keystroke event script) and have the vba call those folder level scripts. I haven't had an opportunity to try that yet.


Code:
    'check if file exists, if it does - randomly assign a numeric sequence at the end.
    strCheckPoint = 0
    If Dir(Environ("USERPROFILE") & "\Downloads\" & descValueTitle & ".pdf") = "" Then
      strCheckPoint = 0
    Else
      answer = MsgBox("A PDF with this name already exists, overwrite?", vbOKCancel)
      If answer = vbOK Then
        strCheckPoint = 0
      Else
        strCheckPoint = 1
      End If
    End If
    If strCheckPoint = 0 Then
      'activate sheets and begin printing
      Sheets("Home").Activate
      ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=Environ("USERPROFILE") & "\Downloads\" & descValueTitle, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

      'add form fields to adobe sheet.
      Dim PDDoc As Object
      Dim AVDoc As Object
      Dim JSO As Object
      Dim formField As Object
      Dim inputPDFfile As String, outputPDFfile As String
      Dim coords() As Variant
      
      Const thlft = 169 'left
      Const thtop = 512 'top
      Const thrt = 300 'right
      Const thebot = 473 'bottom

      inputPDFfile = Environ("USERPROFILE") & "\Downloads\" & descValueTitle & ".pdf"
      outputPDFfile = Environ("USERPROFILE") & "\Downloads\" & descValueTitle & "_temp.pdf"

      Set PDDoc = CreateObject("AcroExch.PDDoc")
      Set AVDoc = CreateObject("AcroExch.AVDoc")
    
      If PDDoc.Open(inputPDFfile) Then
        Set JSO = PDDoc.GetJSObject
        '1st signature field
        coords = Array(thlft, thtop, thrt, thebot)
        Set formField = JSO.addField("authorize_signature", "signature", 0, coords)   '0 = 1st page
        formField.StrokeColor = JSO.Color.transparent 'StrokeColor sets the border and text colours of the field
        '2nd signature field
        coords = Array(thlft + 131, thtop, thrt + 127, thebot)
        Set formField = JSO.addField("sca_signature", "signature", 0, coords)   '0 = 1st page
        formField.StrokeColor = JSO.Color.transparent 'StrokeColor sets the border and text colours of the field
        '1st date field
        coords = Array(thlft + 258, thtop - 26, thrt + 180, thebot)
        Set formField = JSO.addField("approved_date", "text", 0, coords)   '0 = 1st page
        formField.textSize = 6
        formField.textFont = "Arial"
        formField.StrokeColor = JSO.Color.transparent 'StrokeColor sets the border and text colours of the field
        '2nd date field
        coords = Array(thlft + 311, thtop - 26, thrt + 242, thebot)
        Set formField = JSO.addField("sca_date", "text", 0, coords)   '0 = 1st page
        formField.textSize = 6
        formField.textFont = "Arial"
        formField.StrokeColor = JSO.Color.transparent 'StrokeColor sets the border and text colours of the field

        If PDDoc.Save(1, outputPDFfile) Then
          PDDoc.Close
          AVDoc.Open outputPDFfile, vbNullString
          AVDoc.BringToFront
          'MsgBox "Created " & outputPDFfile
          AVDoc.Close False
        Else
          MsgBox "Unable to save " & outputPDFfile
        End If
      End If 'end if open input file
      Dim Shex As Object
      Set Shex = CreateObject("Shell.Application")
      Shex.Open (outputPDFfile)
 

neuroman9999

Member
Local time
Today, 06:34
Joined
Aug 17, 2020
Messages
836
have you received a solution yet? I thought Richard might have helped, but it does not look like he responded:
 

Users who are viewing this thread

Top Bottom