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

Compare PDF fields with imported xml in a loop

Community Beginner ,
Oct 05, 2016 Oct 05, 2016

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

TOPICS
Acrobat SDK and JavaScript
657
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

correct answers 1 Correct answer

Community Beginner , Oct 06, 2016 Oct 06, 2016

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.

Translate
Community Expert ,
Oct 06, 2016 Oct 06, 2016

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.

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 Beginner ,
Oct 06, 2016 Oct 06, 2016

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.

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 ,
Oct 06, 2016 Oct 06, 2016

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

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 Beginner ,
Oct 06, 2016 Oct 06, 2016
LATEST

Thank you

Ups, too many trees in a forest 😉

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