These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adobe XML Form Object Model Nightmare

Mambogumbo
Registered: Jun 15 2010
Posts: 4
Answered

I am trying to manipulate an adobe XML Form (Dynamic) using VB.net. Ultimately I want to put data into a template and save it. I am not sure if resolveNode is the best method to use, but nothing else seems to work. here are my problems...
1) resolveNode() yields a field object equal to Nothing
2) resolveNodes() seems to work, at least the field object gets set
3) Field.rawValue doesn't work - it produces an error indicating a property or method that it doesn't recognize.
4) I can manipulate a static form just fine, but I absolutely have tried everything to put data into a dynamic one and keep running into road blocks.

Dim app As Acrobat.CAcroApp
Dim pddoc As Acrobat.CAcroPDDoc
Dim js As Object
Dim Field As New Object

app = CreateObject("AcroExch.App")
pddoc = CreateObject("AcroExch.PDDoc")
If pddoc.Open("c:\Template.pdf") Then
js = pddoc.GetJSObject
If Not js Is Nothing Then
If js.dynamicxfaform Then
Field= js.xfa.resolveNodes("hh_FirstName")
Field.rawValue = "John"
End If
js.SaveAs("C:\Test.pdf")
End If
End If

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It is not a good idea to run JS code directly in a VB program, particularlly a .Net program. One issue is that VB and JS Data types are only compatible for the simple types. Another issue is that non-generic JS objects cannot be transfered across the ActiveX boundary. And there are other issues with function binding.

To do this the JavaScript code must be placed in a folder level function, then the VB calls the function. That way all JavaScript operations are executed in the context of Acrobat, and there are no incompatiblilities.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Mambogumbo
Registered: Jun 15 2010
Posts: 4
Thom,

Thank you for that great answer. Your time, expertise and eloquence are appreciated.

I understand what you are saying about storing the code in the PDF and just using VB.net to call the function. However, is this the best way to do what I am wanting to do? If this were a static form I would use IAC Form Library to grab the form from an open AVDOC, instantiate each field and fill it with data then save the newly populated form with PDDOC. This method won't work however with a dynamic PDF Form - for dynamic forms fields don't exist as objects until the form is rendered.

So as far as I know my only remaining option is to use the JSObject.

Am I correct in this assumption?

And if I am correct in this assumption, then would you suggest that...
-I create a JS function in the PDF using resolveNode(arg1) and .rawValue=arg2
or
-Would it be better to use the .importData() function

?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I wasn't suggesting creating a script in the PDF. A folder level script is in a ".js" file in a special folder in the Acrobat directory. Folder level scripts have a big advantage because they are privileged. Here's an article on it:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts

And yes, this is the best methodology. The Forms API only applies to the AcroForm model, not the LiveCycle model. In fact, even though the Forms API will appear to work for a static LiveCycle form it does not. LiveCycle form data resides in the data model, not in the form fields and the Forms API only modifies the form fields.

Importing data is an excellent option. It's the best choice if the data is already suitable for placing in an XML file.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script