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

AddScript Method... need help on syntax here:

Benjamin
Registered: Nov 10 2009
Posts: 13
Answered

How to I get this to populate the PDF's in batch mode here.
I've got 1000+ documents. Each needs this javascript embeded in it.
It's not working... think It's the syntax or something like that.

Would someone please explain how to get all this code to equal a variable, and
how do you do the next line featuer, similiar to VBA & _
which lets you separate code down a line but not break the code.

Quote:

var cScriptName = "LoadDate";

var cScriptCode = "//Get System Date and Populate Field called todaysdate
var bAlreadyOpened;
function getsysDate()
{
if(bAlreadyOpened != "true")
{
var d = new Date();
var sDate = util.printd("mm/dd/yyyy", d);
this.getField("todaysdate").value = sDate;
bAlreadyOpened = "true";
}
else
{
}
}
getsysDate();";

this.addScript(cScriptName, cScriptCode);

My Product Information:
Acrobat Pro 8.1.2, Windows
Benjamin
Registered: Nov 10 2009
Posts: 13
Sorry, That PDF link doesn't work for me. Looked it up on google, but don't find anything about addscript method.

What I'm trying to do is add a script into the document level of a PDF, via the batch processing feature.
Benjamin
Registered: Nov 10 2009
Posts: 13
We'll I finally figured it out. Got to use the \n character and the quotes correctly.

Also see post: http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=16940

Quote:
Note for both methods you need to create a string variable that has the value of the entire script to be added not just one line of the script. The JavaScript Reference contains information on how to include special control characters like quotes and new lines within a string variable.
Quote:
The Newline Character<\b>To keep long concatenation output readable, JavaScript provides two ways to create line breaks within your string. The first is the newline character ( \n ). The newline character creates line breaks within the output of a string, be it simply text or JavaScript-generated HTML.

Here is a long string without line breaks:
var noBreaks = "Hello World. My name is Jennifer. What is your name?"

Long String without Line Breaks
Now see what happens to the same string when line breaks are included:
var withBreaks = "Hello World. \nMy name is Jennifer. \nWhat is your name?"

Long String with Line Breaks
Nesting Opposite Quotes

Quote:
String values can be surrounded by either single quotes or double quotes. Except in the case of event handlers which always surround their values in double quotes, which type of quote you use is entirely up to you.Which type of quote you use to surround your nested string is determined by the type of quote surrounding its containing string. A nested string is surrounded by the oppisite kind of quote which surrounds its containing string. I call this "quote swapping". In other words, if my outer string is contained by double quotes, my inner string must be contained by single quotes, and vice versa.

Nest single and double quotes as follows:
var beasty = "He said 'howdy', I said 'hi'." // nesting single quotes within double quotes

var boys = 'He said "howdy", I said "hi".' // nesting double quotes within single quotes

Show me the string
http://jennifermadden.com/javascript/escapeCharacter.php

Quote:
//Final Javascript code for Word to PDF Batch Process
var cScriptCode =" \n var bAlreadyOpened = new Boolean(false);\n function getsysDate() \n { \n if(bAlreadyOpened != true)\n {var d = new Date();\n var sDate = util.printd('mm/dd/yyyy', d);\n this.getField('todaysdate').value = sDate;\n AlreadyOpened = true;\n }\n else \n {\n }\n };\n getsysDate();\n //Get System Date and Populate Field called todaysdate\n //Code by Benjamin 2009\n"

this.addScript("getSysDate", cScriptCode);