Copy link to clipboard
Copied
I have a loop to iterate through all of the fields and copy them from a target pdf to the current pdf.
This currently works well with manually calling the fields, and with console.log within the loop. But as soon as the field.value is updated with the field.value of the other pdf the software crashes (infinite loop?). It even crashes if the field.value is manually set for all fields. I must be missing something simple..
Here is my code:
thisDoc = this;
var docName = app.browseForDoc();
app.openDoc(docName.cPath);
var d = app.activeDocs;
var thatDoc = d[d.length-1];
var i = 0;
while (i<thatDoc.numFields){
var oldName = thatDoc.getNthFieldName(i);
var old = thatDoc.getField(oldName);
if(old.type == "text"){
if (thisDoc.getField(oldName) != null){
var cur = thisDoc.getField(oldName)
cur.value = old.valueAsString;
}
} i++;
}
thatDoc.closeDoc();
Any help would be appreciated.
Found the answer - the javascript api for adobe is single threaded, and as such a loop that relies on the commit chain (on a button/field object) will always fall outside of that commit chain if it's too long (I think!).
Creating this at a document level, after stuffing some lists, seemed to work perfectly well.
Copy link to clipboard
Copied
Try simplifying that first block of code to:
thisDoc = this;
var docName = app.browseForDoc();
var thatDoc = app.openDoc(docName.cPath);
var i = 0;
Copy link to clipboard
Copied
This is something I tried a little while ago, and it just doesn't access the other file 'thatDoc' after opening.
It's also not why this loop isn't working - as the code works great when printing instead of changing values.
I appreciate the idea though - and it's also something I can do within the loop - but I'm keeping it obtuse to try and see what does and doesn't work. Thanks!
Copy link to clipboard
Copied
Found the answer - the javascript api for adobe is single threaded, and as such a loop that relies on the commit chain (on a button/field object) will always fall outside of that commit chain if it's too long (I think!).
Creating this at a document level, after stuffing some lists, seemed to work perfectly well.