Copy link to clipboard
Copied
Hi.
Is it possible to fill in a text field an xml export and after that i can press a button "calculate"
an for example the button search a specified text from the xml export and fill it to the right form field?
sry, bad english, i hope you understand what i mean.
exp.
<Auftragsnummer_Fremdsystem>KKU00123456</Auftragsnummer_Fremdsystem>
so fill "KKU00123456" in an extra form field.
eMd
Copy link to clipboard
Copied
Just took a look at the E4X reference and it seems to be easier then I thought.
Here is a script you can put on a button that will auto fill a form field from XML entered into a different field
var myXML = XML(this.getField("XMLField").value;
this.getField("OtherFormField").value = myXML..Auftragsnummer_Fremdsystem;
You'll need to change the form field names to match the ones on your form.
Copy link to clipboard
Copied
HI,
Can you confirm the version of the software and the operating system you are using?
I am not sure I fully understand your question but it looks like you will need to create a complex script to get the button to work. Another challenge will be to allow your pdf to connect to a specific external file, which is not always possible for other users.
Copy link to clipboard
Copied
i use windows 10 enterprise ans adobe acrobat standard 2017.011.30142
and every user will get the xml data to the clipboard and can paaste it in their pdf file.
Copy link to clipboard
Copied
Yes, this is possible. There are a couple of different ways to do this.
1. If the XML tag matches a field name, and the XML uses a simple flat gramar, then importing the XML will automatically fill the field with the same tag name.
2. Use Acrobat JavaScript to open the XML file and parse out the data.
Depending on how you want to do this, Privilege may be required, meaning that there are certain operations that cannot be done in from within a PDF scripting context, such as silently opening an XML file from the user's file system.
However, if the XML data is text in a form field, then there is no problem.
Copy link to clipboard
Copied
But is it not possible that the button reads the content of the field and fills the corresponding values in certain fields? It always has to work with an xml file?
Copy link to clipboard
Copied
If the XML data is pasted into a field on the form, then it is very easy for a script to read the XML out of the field, parse it, and then fill another field with the results.
Acrobat includes the deprecated E4X XML model. It's an easy way to parse XML.
https://en.wikipedia.org/wiki/ECMAScript_for_XML
Copy link to clipboard
Copied
Thank you very much. Are there any examples I can use as a guide? Unfortunately I am not a programmer, but I would like to make the work for my 2 colleagues a little easier.
Copy link to clipboard
Copied
You'll find tutorials on E4X here:
https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X
However, if you are not a programmer then this may not help much. PM me if you are interested in hiring a developer.
Copy link to clipboard
Copied
Just took a look at the E4X reference and it seems to be easier then I thought.
Here is a script you can put on a button that will auto fill a form field from XML entered into a different field
var myXML = XML(this.getField("XMLField").value;
this.getField("OtherFormField").value = myXML..Auftragsnummer_Fremdsystem;
You'll need to change the form field names to match the ones on your form.
Copy link to clipboard
Copied
var myXML = XML(this.getField("Daten").value);
this.getField("AuftragsNrFremdsys").value = myXML.Auftragsnummer_Fremdsystem;
I tried the following code.
Unfortunately it does not work.
Thank you very much for your advice, I will read myself in the reference, maybe I will find the error.
Copy link to clipboard
Copied
You'll need to look in the console window to see if any errors are being reported.
In fact, the console window is where you want to testing out and developing this code.
You'll find a tutorial here on how to use it:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
However, you missed a very important bit in the code I posted. There are two periods ".." separating the XML object form the tag reference.
Copy link to clipboard
Copied
I corrected the error, but the console writes "Syntax error"
Copy link to clipboard
Copied
Try running just the first line of code in the Console window. What you want to do is verify that the XML text from the form field is being parsed.
Copy link to clipboard
Copied
ok, first line without problem.
I copied the rest of it, but my field remains empty. But I have no more errors in the console
Copy link to clipboard
Copied
Now, I want you to run two separate lines in the console and post the results here.
The first line is this
myXML..Auftragsnummer_Fremdsystem
If this returns nothing
Then run this line, it should print out the entire XML.
myXML
Copy link to clipboard
Copied
ok, so i understand how it works with troubleshooting.
myXML
brought no result in the console. Apparently the field is not parsed
Copy link to clipboard
Copied
What happens when you execute this line in the console
this.getField("Daten").value
Copy link to clipboard
Copied
Sorry i learn now 🙂
this result is the text from the field
if i post this line in console
var myXML = XML(this.getField("Daten").value)
i get the following answer:
SyntaxError: invalid XML tag syntax
undefined
i played a litte more:
XML(this.getField("Daten").value)
Test123i filled the text field Only with
<Ordnungsnummer>Test123</Ordnungsnummer>
Copy link to clipboard
Copied
Ok, so i know the Problem.
I can only parse one <></>
if there a more than one <a>a</a><b>b</b> i get an error...
so i cant parse a whole xml-data with lots more <></>...
Copy link to clipboard
Copied
You must use the correct XML syntax like this:
<top><a>a</a><b>b</b></top>
Copy link to clipboard
Copied
The XML object can parse huge blocks of complex XML. The problem is not the function, the problem is the XML, it is incorrect. I would suggest you find the error in the XML code.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more