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

Can't set certain FreeText Properties with javascript in Acrobat 7.1.0

tmdivine
Registered: Jun 23 2009
Posts: 2
Answered

I'm trying to place a FreeText annotation on a number of drawings using javascript. I can control almost all of the properties of the annotation, except textSize and alignment.

Here's a simple sample program that doesn't work, copied straight from the Acrobat JavaScript Scripting Reference, with the exception of the contents field, which I added:

// Create FreeText annotation with Helvetica
var annot = this.addAnnot({
page: 0,
type: "FreeText",
textFont: font.Helv, // or, textFont: "Viva-Regular",
textSize: 10,
rect: [200, 300, 200+150, 300+3*12], // height for three lines
width: 1,
alignment: 1,
contents: "Test Text." });

What I get is an otherwise expected textbox with 9 point type, left justified. My reading of the Scripting Reference tells me that I should get 10 point type, centered. If I change the textSize or alignment parameters, I still get 9 point type, left-justified. These results are consistent with my other attempts to control font size and alignment.

I suspect that I'm either missing something, or that these parameters aren't actually supported, or that the documentation isn't correct.

Thanks for any help.

My Product Information:
Acrobat Standard 7.0.9, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This seems to be an issue with the ordering of operations. If you set the Text size and font before setting the contents it works, instead of specifying it in the "addAnnot" function. Like this:

annot = addAnnot(...);
annot.textSize = 10;
annot.textFont = ...;
annot.contents = "...";

I'm using Acrobat 8 Pro. Unfortunately, the alignment parameter does not seem to work at all when set from JavaScript. This is definately a bug. I haven't tried it in Acrobat 9 to see if it's been fixed, but this is exactly the kind of thing that slips by from version to version.

Have you tried using the "richContents" property instead of setting the annot level properties? You might have better luck with it

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mczajka
Registered: Oct 11 2005
Posts: 29
I'm having some issues with this with 9.4. I can create and set properties of an annotation from an Acrobat form button with few problems, but when I run in batch, I cannot set the Subject and Contents for some reason. Author is fine.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I did a test and I'm not seeing the issue. What kind of annotation are you creating? What is the sequence of operations? Can you post the code?


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script