Copy link to clipboard
Copied
I've defined a function thusly:
//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
//<Document-Level>
//<ACRO_source>set_all_fields</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:set_all_fields ***********/
function set_all_fields()
{
for(var n; n<n; n++) {
var fieldName = getNthFieldName(n);
var field = getField(fieldName);
console.println(fieldName);
switch(field.type) {
case 'text' :
field.fontFamily = 'Source Sans Pro';
field.fontSize = 9;
break;
case 'checkbox':
field.style = style.ch;
break;
default: console.println(field.type);
break;
}
}
}
How do I call this function from the debugger? All I get is undefined in the console, which lets me believe that the function could not be find
Copy link to clipboard
Copied
I hope you're not editing the scripts via the Edit All JavaScripts command. That can seriously screw up the file, sometimes beyond repair. Use ONLY the Document JavaScripts command to add, edit or delete the doc-level scripts.
Copy link to clipboard
Copied
To answer my question:
Under "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts" create a file with a JavaScript extension (.js) Contents of this file:
/* inside C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts */
app.addMenuItem({
cName: "Set Fields",
cParent: "Edit",
cExec: "set_all_fields();"
});
function set_all_fields()
{
console.show();
for(var n=0; n<this.numFields; n++) {
var fieldName = this.getNthFieldName(n);
var field = this.getField(fieldName);
console.println(fieldName);
switch(field.type) {
case 'text' :
field.textFont = 'Arial';
field.textSize = 9;
break;
case 'checkbox':
field.style = style.ch;
break;
default: console.println(field.type);
break;
}
}
}
which will set the font family and size for all text fields and a check mark for all checkboxes..
Copy link to clipboard
Copied
Btw in the Debugger the list under scripts is empty:
Copy link to clipboard
Copied
Have you opened the document?
Copy link to clipboard
Copied
How does you call the function?
Info: following will not work:
for(var n; n<n; n++)
Copy link to clipboard
Copied
Thanks , I know. I want to run it in the debugger cause that is what debuggers are for.
How do I debug this function?
Copy link to clipboard
Copied
//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
//<Document-Level>
//<ACRO_source>set_all_fields</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:set_all_fields ***********/
function set_all_fields()
{
console.show();
for(var n; n<numFields; n++) {
var fieldName = getNthFieldName(n);
console.println(fieldName);
var field = getField(fieldName);
switch(field.type) {
case 'text' :
field.fontFamily = 'Source Sans Pro';
field.fontSize = 9;
break;
case 'checkbox':
field.style = style.ch;
break;
default: console.println(field.type);
break;
}
}
}
//</ACRO_script>
//</Document-Level>
Copy link to clipboard
Copied
Use this:
for(var n = 0; n<numFields; n++) {
Copy link to clipboard
Copied
"Undefined" does not mean that it didn't find the function. It's normal. To try this out I suggest you add an app.alert call to your document level script.
Copy link to clipboard
Copied
I hope you're not editing the scripts via the Edit All JavaScripts command. That can seriously screw up the file, sometimes beyond repair. Use ONLY the Document JavaScripts command to add, edit or delete the doc-level scripts.
Copy link to clipboard
Copied
To answer my question:
Under "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts" create a file with a JavaScript extension (.js) Contents of this file:
/* inside C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts */
app.addMenuItem({
cName: "Set Fields",
cParent: "Edit",
cExec: "set_all_fields();"
});
function set_all_fields()
{
console.show();
for(var n=0; n<this.numFields; n++) {
var fieldName = this.getNthFieldName(n);
var field = this.getField(fieldName);
console.println(fieldName);
switch(field.type) {
case 'text' :
field.textFont = 'Arial';
field.textSize = 9;
break;
case 'checkbox':
field.style = style.ch;
break;
default: console.println(field.type);
break;
}
}
}
which will set the font family and size for all text fields and a check mark for all checkboxes..
Copy link to clipboard
Copied
Thanks for the tip @try67

