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

Read xml for text field

Community Beginner ,
Nov 12, 2017 Nov 12, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
567
Translate
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 12, 2017 Nov 12, 2017

This JavaScript code will not work in Adobe Acrobat.

Translate
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 13, 2017 Nov 13, 2017
LATEST

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

Translate
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