Skip to main content
Known Participant
November 12, 2017
Question

Read xml for text field

  • November 12, 2017
  • 2 replies
  • 595 views

Read an attribute value of the XML file

File a.xml, the path is: C:\Program Files\Adobe\Adobe Photoshop CC 2018\Presets\Scripts\a.xml

The content of a.xml is:

<Mark>

<Widths>600</Widths>

<Hights>591</Hights>

<RES>254</RES>

<Name>029</Name>

<CWidths>2</CWidths>

<CHights>2</CHights>

<Quxi>0</Quxi>

<Date>29</Date>

<Cwei>20</Cwei>

<JY>029</JY>

</Mark>

i want get Date.value  for text field by javascript

i try:

var f = new File('/C/Program Files/Adobe/Adobe Photoshop CC 2018/Presets/Scripts/Proof_2.0.xml'); 

f.open('r'); 

var xml = new XML( f.read() ); 

f.close(); 

var Widths = xml.child('Widths'); 

event.value=Widths;

but text field no value

pls help me

e pls help me

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 13, 2017

As Bernd says, the Acrobat javaScript model is a bit limited, but is can certainly handle an xml file.

However, there is a very simple way to do this manually. If your text fields on the PDF exactly match the names of the Tags in the XML then this will work.

1. Rename the "Mark" tag to "fields"

2. Search for the "import Data" tool in Acrobat. This will  be on the "Prepare Forms" panel

3. Run "import data" and select "XML" in the data type dropdown.

That's it.

Unfortunately there is no JS command for just importing xml data. If you reformatted the XML in XFDF gramar, then there is a command for loading XFDF.

But if you want to keep the formatting, you can automate loading with JavaScript by reading the xml file data and parsing it with one of the built-in XML parsers, and then writing each data field separately. That's more code than I want to write here. I have code and an article on this topic at www.pdfscripting.com

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
November 12, 2017

This JavaScript code will not work in Adobe Acrobat.