These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add combo box via Javascript and Action Wizard

coppercarla
Registered: Apr 8 2009
Posts: 8

I'm not a scripter, so I'm turning to the forum for help.
 
Using Acrobat X, I want to create an Action Wizard to add a pre-populated combo box to a PDF. (Our printing company needs to specify a "Printed In" Country on the page when they print it - could be printed in US, China, or elsewhere).
 
The AW side is easy, but I know that it will need to call a javascript to create the combo box. It's the javascript that I need help with.
 
From other script samples I looked at, I can figure out how to set the values of the field and its location - it's the code to create the combo box I need, which is probably only a couple of lines. Anyone willing to help?
 
Combo Box Values:
China
U.S.A.
Enter Country Name
 
Location is bottom left of form, I'll have to fine tune the exact location.

My Product Information:
Acrobat Pro Extended 10.1, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
With a few modifications to the example script and using the option to use the parameters for the "addField" method:

var inch = 72; // points per inch
var page = 0; // zero based page for field
// options for selection by the field
var aOptions = new Array("China", "U.S.A.", "Enter Country Name");

// Position a rectangle (.5 inch, .5 inch)
var aRect = this.getPageBox( {page: page} );
aRect[0] += .5 * inch;// from upper left hand corner of page.
aRect[2] = aRect[0] + 1.5 * inch;// Make it 1.5 inch wide
aRect[1] -= .5 * inch;
aRect[3] = aRect[1] - 24;// and 24 points high

// Now construct a combo box
var f = this.addField({cName: "Country", cFieldType: "combobox", nPageNum: page, oCoords: aRect})
// complete the properties of the field
f.delay = true; // turn off display refresh
f.borderStyle = border.s; // border style
f.strokeColor = color.black; // border color - black
f.lineWidth = 2; // border width
f.fillColor = color.transparent; // background color - clear
f.setItems(aOptions); // set options for selection
f.editable = true; // allow edit of options
f.textSize = 10; // 10 point size for text
f.textColor = color.black // text color - black
f.textFont = font.Times; // font name
f.delay = false; // restore display refresh


George Kaiser

coppercarla
Registered: Apr 8 2009
Posts: 8
Thank you so much for your help!

I've modified the script for my document, but while the box your script creates will print the content of the combo box, mine will not. :-/

Also, I'd like the text to be Arial Bold if I can -- I tried changing the font to BoldArial and ArialBold without success), and to set a color value for the text to match what is in our document. The custom color would be defined as:

color.mynavy = new Array("RGB", 0, 0, 128);

Thx,
Carla

----------------------------------------------

var inch = 72; // points per inch
var page = 0; // zero based page for field
// options for selection by the field
var aOptions = new Array("China", "U.S.A.", "Enter Country Name Here");


// Position a rectangle (.5 inch, .5 inch)
var aRect = this.getPageBox( {page: page} );
aRect[0] += 1.875 * inch;// from upper left of page.
aRect[2] = aRect[0] + 1.25 * inch;// Make it 1.5 inch wide
aRect[1] -= 10.59 * inch;//from top
aRect[3] = aRect[1] - 18;// and 24 points high

// Now construct a combo box
var f = this.addField({cName: "Printed_In", cFieldType: "combobox", nPageNum: page, oCoords: aRect})

// complete the properties of the field
f.delay = true; // turn off display refresh
f.borderStyle = border.s; // border style
f.strokeColor = color.red; // border color - red
f.lineWidth = .25; // border width
f.fillColor = color.transparent; // background color - clear
f.setItems(aOptions); // set options for selection
f.editable = true; // allow edit of options
f.textSize = 7; // 7 point size for text
f.textColor = black// text color - black
f.textFont = font.Arial; // font name
f.display = display.visible
f.delay = false; // restore display refresh


gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can set the display property to "display.noPrint"

On my system,Windows XP with Acrobat 8 Pro, using the following code in the JavaScirpt console for field "Text1":

this.getField("Text1").textFont;

I get the response;

Arial,Bold

So I can use the following code to set the font to the arbitrary font:

this.getField("Text1").textFont = "Arial,Bold";

You can change the above script for your needs.

George Kaiser

coppercarla
Registered: Apr 8 2009
Posts: 8
George - please forgive my ignorance, but I'm not a programmer. I've tried several ways to get feedback on this in the console, and all I'm getting is a return result of "undefined."

I did find that the reason that my field wasn't printing was the Arial definition - there must be a variation on the name that is appropriate. When it was changed back to plain Times, it worked.


try67
Expert
Registered: Oct 30 2008
Posts: 2398
"undefined" is just a general term that means the script completed without returning any value.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com