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

Write to XFA form using VBA

New Here ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

Hi, 

Hoping somebody can help with a VBA (using Excel) question. I have reasonable understanding of VBA but have never worked with PDF forms until now.

I have written VBA code to extract field names from a PDF document (Adobe XML form created in Adobe LiveCycle I beleive).

Example field name = "data[0].mainpage[0].header[0].Table1[0].Row4[0].SUPPLIER_CONTACT[0]"

 

How can I get the VBA to write to the PDF form fields?

 

I have tried:

fld.value = "TEXT"

jso.xfa.form("data[0].mainpage[0].header[0].Table1[0].Row4[0].SUPPLIER_CONTACT[0]").rawvalue = "TEXT"

but these do not appear to work. No error messages.

 

For info, here is the VBA for getting the field names:

Public Function PDFForm2()

Dim acroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim jso As Object, fld As Object, page As Object, xfaObj As Object
Dim numFields As Integer, FldNum As Integer, numFldNodes As Integer, numPages As Integer, PageNum As Integer
Dim fldName As String, FormPath As String, XML As String, XMLPath As String

Set acroApp = CreateObject("AcroExch.App")
Set PDDoc = CreateObject("AcroExch.PDDoc")
FormPath = "C:\Temp\BlankConForm.pdf"

If Not PDDoc.Open(FormPath) Then
MsgBox "Couldn't open PDDoc", vbInformation, "ERROR in GetFillablePDFNames"
Exit Function
End If

Set jso = PDDoc.GetJSObject
'jso.console.Show
jso.console.Clear
'acroApp.Show

Range("A1").Select

numPages = jso.xfa.host.numPages
numFields = jso.numFields

For FldNum = 1 To 100
fldName = jso.GetNthFieldName(FldNum)
ActiveCell.Value = fldName

Set fld = jso.getfield(fldName) 'set a field object
ActiveCell.Offset(0, 1).Value = fld.Value
ActiveCell.Offset(1, 0).Select


Next FldNum

PDDoc.Save 1, "C:\Temp\BlankConForm2.pdf"

MsgBox "Finished"
End Function

TOPICS
Windows

Views

258

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
LEGEND ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

A comment, not a solution. The code to get the number of fields does not use the JSO interface, it uses the regular Acroform interface. This will work in at least some cases, because XFA forms may "shadow" the fields into a dummy or static Acroform fields.  The interface for them, jso.xfa is outside my experience; it isn't documented in the Acrobat JavaScript API. Do you have an XFA JavaScript reference (not really our area, but a link might be interesting)?

Votes

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
New Here ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

Thanks for your respose. The only references I am running currently in this VBA are:

- Visual Basic For Applications

- Microsoft Excel 16.0 Object Library

- OLE Automation

- Microsoft Office 16.0 Object Library

- Adobe Acrobat 10.0 Type Library

Votes

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
LEGEND ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

Sorry, I mean actual documentation. Here is the (acroform) JavaScript API Reference https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf

Votes

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
New Here ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

Votes

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 ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

LATEST

XFA scripting is more complex than regular AcroForm scripting and by necessity involves using a lot of XML objects. These do not translate well across the VBA/AcroJS boundary.  It would be much easier and more productive for you to develop the code that works on the XFA model first in the Acrobat Console window, and then as a folder level function. Then call this function from VBA, passing in simple scaler arguments.

 

XFA development is very different than for an AcroForm.  You'll find several articles here that include both AcroForm and XFA examples.

https://www.pdfscripting.com/public/110.cfm

 

For example, this one on lists, that includes some discussion on XFA programing.

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

 

   

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

Votes

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