Scan a document for collecting the values of some fields

Participant ,
Oct 25, 2017

Copy link to clipboard

Copied

I created a document (I don't know how to upload a pdf, therefore you can access a sample via Dropbox : https://www.dropbox.com/s/fni2eur4t1w48qa/Data_collecting%20.pdf?dl=0) of several pages and I need to extract the value of a field which can appear on some of the pages.

These fields are named:

Source.0

Source.1

Source.2

etc.

Page one can start with the field Source.2

the following page can be free of such a field

The field Source.8 may appear on page 3

etc.

I am trying to scan each page for finding a field starting with "Source." and if found, to copy its value to another field starting with "Result." but with the same index :

Result.3 value = Source.2 value

Result.10 value = Source.10 value

etc.

Please pay attention : the fields "Source." contain fixed references and the displayed pages are issued from templates. Therefore, I need to know which reference fields appear ont the displayed pages, and then capture their value. The list of "Result" will show part of the fields with a value, and the others must stay empty.

Here below is the beginning of my story... but I miss too much knowledge to continue...

  

Can someone help me to finalize it ?

Many thanks in advance.

*********************************************************************

ATTEMPT to display the value in app.alert (!!! infinite loop !!!

**********************************************************************

var
nameField="";

for (var a
= 0; a < this.numPages; a++) {

for (var i
= 0; i < this.numFields; i++) {

              var
nameField=this.getNthFieldName(i);

              var f = this.getField(nameField);

              var str=nameField;

              var OK =
str.indexOf("Source.");

              if (OK > -1) {

                            app.alert(this.getField(nameField).value);

                                           //break;

                            }

              }

}

@ Test Screen Name :

I have to keep the same name used in the templates.and I agree with you regarding the difficulty.

That is the reason why I'm kindly asking some help

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

193

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Scan a document for collecting the values of some fields

Participant ,
Oct 25, 2017

Copy link to clipboard

Copied

I created a document (I don't know how to upload a pdf, therefore you can access a sample via Dropbox : https://www.dropbox.com/s/fni2eur4t1w48qa/Data_collecting%20.pdf?dl=0) of several pages and I need to extract the value of a field which can appear on some of the pages.

These fields are named:

Source.0

Source.1

Source.2

etc.

Page one can start with the field Source.2

the following page can be free of such a field

The field Source.8 may appear on page 3

etc.

I am trying to scan each page for finding a field starting with "Source." and if found, to copy its value to another field starting with "Result." but with the same index :

Result.3 value = Source.2 value

Result.10 value = Source.10 value

etc.

Please pay attention : the fields "Source." contain fixed references and the displayed pages are issued from templates. Therefore, I need to know which reference fields appear ont the displayed pages, and then capture their value. The list of "Result" will show part of the fields with a value, and the others must stay empty.

Here below is the beginning of my story... but I miss too much knowledge to continue...

  

Can someone help me to finalize it ?

Many thanks in advance.

*********************************************************************

ATTEMPT to display the value in app.alert (!!! infinite loop !!!

**********************************************************************

var
nameField="";

for (var a
= 0; a < this.numPages; a++) {

for (var i
= 0; i < this.numFields; i++) {

              var
nameField=this.getNthFieldName(i);

              var f = this.getField(nameField);

              var str=nameField;

              var OK =
str.indexOf("Source.");

              if (OK > -1) {

                            app.alert(this.getField(nameField).value);

                                           //break;

                            }

              }

}

@ Test Screen Name :

I have to keep the same name used in the templates.and I agree with you regarding the difficulty.

That is the reason why I'm kindly asking some help

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

194

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2017 0
Most Valuable Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

I don't understand why the page number is important... Don't you just want to copy the value of "Source.X" to "Result.X"?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

Thanks for your Answer.

you are right  : the page number has no importance.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Most Valuable Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

You can use this code to achieve it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/^Result/.test(f.name)) {

        var fname2 = f.name.replace("Result", "Source");

        var f2 = this.getField(fname2);

        if (f2==null) {

            console.println("Error! Can't find: " + fname2);

        } else f.value = f2.value;

    }

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

it does exactly what I expected !

Thank you very much

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

Oops : not true. Sorry.

It works with the sample.

But my final PDF contains ALL the fields "Source" (0, 1, 2, 3, 4 etc.) in the templates.

After I show some of the templates (this.getTemplate...spawn...) , I need to extract the value of the fields which appear only on  the showed pages

The code should do this :
go to page 0
find if there is a field named "Source.#" on it
If yes, copy its value int another field named "Result.#"
# = index. -->  /!\ "Source" and "Result". indexes must match

Go to page 1
etc.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Most Valuable Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

Fields are global. Try and express your algorithm with reference to "fields by name" rather than "fields on a page by name".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

I don't understand what you mean : I will rephrase the question because I may not have been clear :

I created a PDF with 150 templates

Some template bear a field named "Source.#"

Each field "Source.#" is unique

Each field "Source.#" contains a specific and fixed value

Users can copy the templates of their choice (spawn) and display the desired pages

I need to sort a list of the values of the fields "Source.#" appearing only on the pages "spawned".
The ones which remain in the templates "not spawned" are irrelevant.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Adobe Community Professional ,
Oct 26, 2017

Copy link to clipboard

Copied

Do you rename the fields when you spawn the templates?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

No, I don't rename the fields :

this.getTemplate("101").spawn({nPage:this.numPages, bRename:false, bOverlay: false});

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Adobe Community Professional ,
Oct 26, 2017

Copy link to clipboard

Copied

The loops are not infinite.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

I am amazed: the sample available via Dropbox contains this code in the "action" of the button (I deactivated it with "//" on each line because of infinite loop. ( I tested it right now (PC) and I can still observe an inifinte loop...

Do you mean that you did not find an infinite loop using the file and the code ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Most Valuable Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

I recommend you forget about page numbers, and focus on fields. Since you generate the names you can use the name to discover whether it is interesting. If you MUST interest yourself in the page(s) upon which fields appear, you still iterate all the fields but for each field you can inspect the "page" property which is a number or array. This will be much more complicated.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0
Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

@ Test Screen Name :

I have to keep the same name used in the templates.and I agree with you regarding the difficulty.

That is the reason why I'm kindly asking some help

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2017 0