spell methods

addDictionary

customDictionaryClose

ignoreAll

addWord

customDictionaryCreate

removeDictionary

check

customDictionaryDelete

removeWord

checkText

customDictionaryExport

userWords

checkWord

customDictionaryOpen

 

addDictionary

X 

P 

 

X 

Note:Beginning with Acrobat 6.0, this method is no longer supported and always returns false. Use the customDictionaryOpen method instead.

Adds a dictionary to the list of available dictionaries.

A dictionary actually consists of four files: DDDxxxxx.hyp, DDDxxxxx.lex, DDDxxxxx.clx, and DDDxxxxx.env. The cFile parameter must be the device-independent path of the .hyp file, for example, "/c/temp/testdict/TST.hyp". The Spelling plug-in will look in the parent directory of the TST.hyp file for the other three files. All four file names must start with the same unique 3 characters to associate them with each other, and they must end with the dot three extensions listed above, even in Mac OS.

Parameters

cFile 

The device-independent path to the dictionary files.

cName 

The dictionary name used in the spelling dialog box. It can be used as the input parameter to the check, checkText, and checkWord methods.

bShow 

(optional) If true (the default), the cName value is combined with “User: ” that name is shown in all lists and menus. For example, if cName is “Test”, “User: Test” is added to all lists and menus.

If false, this custom dictionary is not shown in any lists or menus.

Returns

false 

addWord

5.0

P 

S 

 

Adds a new word to a dictionary. See also the removeWord.

Note:Beginning with Acrobat 7.0, this method is allowed only during a console or batch event. See Privileged versus non-privileged context for details.

Internally, the spell object scans the user “Not-A-Word” dictionary and removes the word if it is listed there. Otherwise, the word is added to the user dictionary. The actual dictionary is not modified.

For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cWord 

The new word to add.

cName 

(optional) The dictionary name or language code. An array of the currently installed dictionaries can be obtained using dictionaryNames or languages.

Returns

true if successful, otherwise, false.

check

5.0

 

 

 

Presents the Spelling dialog box to allow the user to correct misspelled words in form fields, annotations, or other objects.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

aDomain 

(optional) An array of Doc that should be checked by the Spelling plug-in, for example, form fields or comments. When you do not supply an array of domains, the “EveryThing” domain will be used. An array of the domains that have been registered can be obtained using the domainNames property.

aDictionary 

(optional) The array of dictionary names or language codes that the spell checker should use. The order of the dictionaries in the array is the order the spell checker will use to check for misspelled words. An array of the currently installed dictionaries can be obtained using spell.dictionaryNames or spell.languages. When this parameter is omitted, the spellDictionaryOrder list will be searched followed by the dictionaryOrder list.

Returns

true if the user changed or ignored all the flagged words. When the user dismisses the dialog box before checking everything, the method returns false.

Example

Set the dictionaries, then spell check the comments and form fields of the current document. Reports back to the console.

   var dictionaries = ["de", "French", "en-GB"];

   var domains = ["All Form Fields", "All Annotations"];

   if (spell.check(domains, dictionaries) )

      console.println("You get an A for spelling.");

   else

      console.println("Please spell check this form before you submit.");

checkText

5.0

 

 

 

Presents the spelling dialog box to allow the user to correct misspelled words in the specified string.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cText 

The string to check.

aDictionary 

(optional) The array of dictionary names or language codes that the spell checker should use. The order of the dictionaries in the array is the order the spell checker will use to check for misspelled words. An array of installed dictionaries can be obtained using spell.dictionaryNames or spell.languages. When this parameter is omitted, the spellDictionaryOrder list will be searched followed by the dictionaryOrder list.

Returns

The result from the spelling dialog box in a new string.

Example

Spell check a particular field, and update the spelling in the field.

   var f = this.getField("Text Box")    // A form text box

   f.value = spell.checkText(f.value);  // Let the user pick the dictionary

checkWord

5.0

 

 

 

Checks the spelling of a specified word.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cWord 

The word to check.

aDictionary 

(optional) The array of dictionary names or language codes that the spell checker should use, to check for misspelled words. The spell checker uses the dictionaries in the order they appear in the array. An array of installed dictionaries can be obtained using spell.dictionaryNames or spell.languages. If this parameter is omitted, the spellDictionaryOrder list is searched, followed by the dictionaryOrder list.

Returns

A null object if the word is correct, otherwise an array of alternative spellings for the unknown word.

Example 1

Insert the array of suggested alternative spellings into a list box.

   var word = "subpinna"; /* misspelling of "subpoena" */

   var dictionaries = ["English"];

   var f = this.getField("Alternatives") // Alternative spellings list box
   f.clearItems();

   f.setItems(spell.checkWord(word, dictionaries));

Example 2

The following script marks misspelled words in the document with a squiggle annotation whose contents are the suggested alternative spellings. The script can be executed from the console, as a mouse-up action within the document, a menu, or as a batch sequence.

   var ckWord, numWords;

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

   {

      numWords = this.getPageNumWords(i);

      for (var j = 0; j < numWords; j++)

      {

         ckWord = spell.checkWord(this.getPageNthWord(i, j))

         if ( ckWord != null )

         {

            this.addAnnot({

               page: i,

               type: "Squiggly",

               quads: this.getPageNthWordQuads(i, j),

               author: "A. C. Acrobat",

               contents: ckWord.toString()

            });

         }

      }

   }

customDictionaryClose

6.0

 

 

 

Closes a custom dictionary that was opened using customDictionaryOpen or customDictionaryCreate.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cName 

Dictionary name used when this dictionary was opened or created.

Returns

true if successful, false on failure.

customDictionaryCreate

6.0

 

S 

X 

Use this method to create a new custom dictionary file and add it to the list of available dictionaries.

Note:This method is allowed only during a console or batch event. See Privileged versus non-privileged context for details.

Parameters

cName 

Dictionary name used in the spelling dialog box. It can be used as the input parameter to check, checkText, and checkWord methods.

cLanguage 

(optional) Use this parameter to associate this dictionary with a language. A list of available languages can be obtained from the spell.languages property.

bShow 

(optional) If true (the default), the cName parameter is combined with “User: ” and shown that name in all lists and menus. For Example, if cName is “Test”, “User: Test” is added to all lists and menus. When bShow is false, this custom dictionary is not shown in any lists or menus.

Returns

true if successful, false on failure. This method will fail if the user does not have read and write permission to this directory.

Example

Open a PDF document in Acrobat and execute the following script in the console. This script extracts the first word of each bookmark. If that word is already in a dictionary, it is discarded. An unknown word is added into a newly created dictionary, called JavaScript" in this case.

   spell.customDictionaryCreate("JavaScript", "en", true);

   function GetJSTerms(bm, nLevel)

   {

      var newWord = bm.name.match(re);

      var ckWord = spell.checkWord( newWord[0] );

      if ( ckWord != null )

      {

         var cWord = spell.addWord( newWord[0], "JavaScript");

         if ( cWord )  console.println( newWord[0] );

      }

      if (bm.children != null)

      for (var i = 0; i < bm.children.length; i++)

      GetJSTerms(bm.children[i], nLevel + 1);

   }

   console.println("\nAdding New words to the \"JavaScript\" "
      + "dictionary:");

   var re = /^\w+/;

   GetJSTerms(this.bookmarkRoot, 0);

customDictionaryDelete

6.0

 

S 

X 

Use this method to close and delete a custom dictionary file that was opened by customDictionaryOpen or customDictionaryCreate.

Note:This method is allowed only during a console or batch event. See Privileged versus non-privileged context for details.

Parameters

cName 

The name of the dictionary to be deleted. This is the name used when this dictionary was opened or created.

Returns

true if successful, false on failure. This method will fail if the user does not have sufficient file system permission.

Example

Delete a custom dictionary.

   spell.customDictionaryDelete("JavaScript");

customDictionaryExport

6.0

 

S 

X 

Exports a custom dictionary to a new file that was opened using the spell methods customDictionaryOpen or customDictionaryCreate.

The user is prompted for an export directory, where the custom dictionary is saved as a .clam file using the dictionary name and language specified in customDictionaryCreate. For example, if the dictionary name is “JavaScript” and the "en" language as specified when it was created, the export file name will be JavaScript-eng.clam.

Exported custom dictionaries can be used in subsequent customDictionaryOpen calls.

Note:This method is allowed only during a console or batch event. See Privileged versus non-privileged context for details.

Parameters

cName 

The dictionary name used when this dictionary was opened or created.

Returns

true if successful, false on failure. This method will fail if the user does not have sufficient file system permission.

Example

Export a custom dictionary, which can then be sent to other users. (See the example that follows customDictionaryCreate.)

   spell.customDictionaryExport("JavaScript");

customDictionaryOpen

6.0

 

 

 

Adds a custom export dictionary to the list of available dictionaries. See customDictionaryExport.

Note:A custom dictionary file can be created using the customDictionaryCreate and customDictionaryExport methods.

For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cDIPath 

The device-independent path to the custom dictionary file.

cName 

Dictionary name used in the spelling dialog box. It can be used as the input parameter to check, checkText, and checkWord methods.

bShow 

(optional) If true, the default, the cName parameter is combined with “User: ” and that name is shown in all lists and menus. For example, if cName is “Test”, add “User: Test” is added to all lists and menus. When bShow is false, this custom dictionary is not shown in any lists or menus.

Returns

true if successful, false on failure. This method fails if the user does not have read permission for the file.

Example

This example continues the ones following customDictionaryCreate and customDictionaryExport. It adds a custom export dictionary to the list of available dictionaries.

The user places the custom export dictionary in any folder for which there is read/write permission. A particular choice is the user dictionaries folder, whose location of can be obtained from the app.getPath method.

   app.getPath("user", "dictionaries");

After the export dictionary has been placed, listing it can be made automatic by adding some folder-level JavaScript. The path to the user JavaScripts folder can be obtained by executing

   app.getPath("user", "javascript");

Finally, create a .js file in this folder and add the line

   var myDictionaries = app.getPath("user", "dictionaries");

   spell.customDictionaryOpen( myDictionaries, "JavaScripts", true);

The next time Acrobat is started, the "JavaScript" dictionary will be open and available.

ignoreAll

6.0

 

 

 

Adds or removes a word from the Spelling ignored-words list of the current document.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cWord 

The word to be added or removed from the ignored list.

bIgnore 

(optional) If true (the default), the word is added to the document ignored word list; if false, the word is removed from the ignored list.

Returns

true if successful. This method throws an exception if no document is open.

Example

   var bIgnored = spell.ignoreAll("foo");

   if (bIgnored) console.println("\"foo\" will be ignored);

removeDictionary

X 

P 

 

X 

Note:Beginning with Acrobat 6.0, this method is no longer supported. The return value of this method is always false. Use the customDictionaryClose method.

Removes a user dictionary that was added with addDictionary.

Parameters

cName 

The name of the dictionary to remove. Must be the same name as was used with addDictionary.

Returns

false 

removeWord

5.0

P 

S 

 

Removes a word from a dictionary. Words cannot be removed from user dictionaries that were created using either customDictionaryCreate or customDictionaryExport.

See also addWord.

Note:Internally, the spell object scans the user dictionary and removes the previously added word if it is there. Otherwise, the word is added to the user’s “Not-A-Word” dictionary. The actual dictionary is not modified.

For Adobe Reader, this property is available only for version 7.0 or later.

As of Acrobat 8.1, this method is only permitted to execute through the console or in a batch process.

Parameters

cWord 

The word to remove.

cName 

(optional) The dictionary name or language code. An array of installed dictionaries can be obtained using dictionaryNames or languages.

Returns

true if successful, false otherwise

userWords

5.0

 

 

 

Gets the array of words a user has added to, or removed from, a dictionary. See also addWord and checkWord.

Note:For Adobe Reader, this property is available only for version 7.0 or later.

Parameters

cName 

(optional) The dictionary name or language code. An array of installed dictionaries can be obtained using dictionaryNames or languages. If cName is not specified, the default dictionary is used. The default dictionary is the first dictionary specified in the Spelling preferences dialog box.

bAdded 

(optional) If true, return the user’s array of added words. If false, return the user’s array of removed words. The default is true.

Returns

The user’s array of added or removed words.

Example

List the words added to the “JavaScript” dictionary. (See the example that follows the description of customDictionaryCreate.)

   var aUserWords = spell.userWords({cName: "JavaScript"});

   aUserWords.toSource();