Copy link to clipboard
Copied
Hello,
At the beginning I am a newbie in Acrobat and Javascript.
I have create a PDF-form with Acrobat Pro, my next idea is to fill the PDF with related data via an XML-Import.
Actual I can import the xml and fill the PDF-Fields hardcoded, this works already via Javascript.
My problem actual is, I want to fill the PDF with the XML-data via an for-loop, because we want to use this script in several PDF-forms and not each form has the same amount of fields.
Here my working script:
var xmldoc = util.readFileIntoStream();
var xmlstring = util.stringFromStream();
var myXML = XMLData.parse(xmlstring,false);
var oNode = XMLData.applyXPath(myXML,"//Customer");
this.getField("CustomerName").value=oNode.Customer.CustomerName.value;
this.getField("CustomerStreet").value=oNode.Customer.CustomerStreet.value;
this.getField("CustomerPlace").value=oNode.Customer.CustomerPlace.value;
this.getField("CustomerSiteName").value=oNode.Customer.CustomerSiteName.value;
this.getField("CustomerSiteStreet").value=oNode.Customer.CustomerSiteStreet.value;
this.getField("CustomerSitePlace").value=oNode.Customer.CustomerSitePlace.value;
Here my problem
for(var i=0;i<oNode.length;i++){
if(this.getField(????)==oNode.Order.???){
this.getField(???).value=oNode.Order.???.value;
}
}
I hope anyone understand what I mean and can help me.
thx in advance
Regards
Dirk
Hello try67,
Thank you.
In the first step I see, with getNthFieldName and numFields, all fields of the PDF now, but I have no idea how to access to the fields of the XML.
Thank you in advance.
Copy link to clipboard
Copied
Have a look at the getNthFieldName method and the numFields property of the Document object.
Using these two allows you to get the full list of names of the fields in the file dynamically, so you don't need to hard-code the names into your script.
Copy link to clipboard
Copied
Hello try67,
Thank you.
In the first step I see, with getNthFieldName and numFields, all fields of the PDF now, but I have no idea how to access to the fields of the XML.
Thank you in advance.
Copy link to clipboard
Copied
If the values are all under the same node then you can do it like this (let's say the variable fieldName contains the name of the field you want to access):
oNode.Customer[fieldName].value
Copy link to clipboard
Copied
Thank you
Ups, too many trees in a forest 😉
Find more inspiration, events, and resources on the new Adobe Community
Explore Now