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

How to Populate a Text Field with "Text"

Benjamin
Registered: Nov 10 2009
Posts: 13
Answered

I want to create a text field on all documents within a folder.

I need the text field to say:

Printed Document Only Valid This Date

in the textfield.

I need to do this to thousands of documents.

I know how to create a textfield... but what's the property or method to populate the text
in a text field in Adobe Acrobat?

Sorry new to Javascript here...

My Product Information:
Acrobat Pro 7.0.8, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you need to do this to all files in a folder then I imagine you using a Batch Sequence script?

I also imagine you are using the "addField()" function, this function returns the field object. So your code should look something like this:
var oFld = addField(...);oFld.value = "Printed Document Only Valid This Date";// And so the user can't edit the textoFld.readOnly = true;

since this is for static text on the PDF you should consider using the "addWatermarkFromText()" fucntion.

You can find all the information you need in the Acrobat JavaScript Reference and other documentation.

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

Benjamin
Registered: Nov 10 2009
Posts: 13
This helps....
Okay .value just like VB/VBA okay... They don't have an object library explorer do they?
Anyhow.... thankyou much.

the whole scope is I need to add a system date stamp to the document as well.
Yes, because otherwise a watermark would be just fine. And Having these read only is just fine.

I need to have
Field1 -"Printed Document Only Valid This Date"
size 18
text helvetica
color red
rect: 417, 32, 512, 7.5

field 2 -This is the system's date or today's date. (so that evertime it's opened it shows today's date.)
size 18
text helvetica
color red
rect: 94, 32, 418, 7.5

I tried adding the field, but It keeps adding a field every time the code excutes.

I suppose doing an if statment, if field "field 1" exists then nothing else create field.

Yah... I'll need to do a batch sequence.
Do you recommend using the Acrobat Pro Batch Tool?

Got sysDate already
Quote:
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();
Insert Field
Quote:
var name = "myButton";
var type = "button";
var page = 0;
var location = [800, 472, 172, 400];
var myField = this.addField(name, type, page, location);function New()
{
}
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, I recomend using a script in the Acrobat Pro Batch Processing.

It's easy enough to test for the existance of a field, just do a getField and see if anything is returned. But checking to see if a field is on a particular page takes a bunch more code.
One of the problems with adding a field is that it's only added to one page at a time.

Watermarks are added to a all pages or a page range, so you take care of the whole docuemnt in one line of code. You can also add more than one by renaming the OCG to which the watermark is attached.

Take a look at this article:
http://www.acrobatusers.com/tutorials/2006/create_use_layers

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

Benjamin
Registered: Nov 10 2009
Posts: 13
Thomp: so then I could add a layer with a read-only field "Valid only on date"
and a field "Current System Date" on a separate layer.
As I'd like to add it to all pages in a document.
You recommend using layers and watermark to do that.

Workflow is really important, so I appreciate your help here.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It's not a field. A watermark is text that's added directly into the Page Content. Read the article and try it out to see what you think.

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

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
A Watermark is a a layer, but it is a special variation of a layer that the end user can not easily turn on or off.

You could also add a text field and then flatten the PDF if there are no comments or other fields in the PDF.

George Kaiser

Benjamin
Registered: Nov 10 2009
Posts: 13
So a watermark is editable then, it's not static, right?

If a watemark is a layer, then I can put an auto-updating field on it correct?
So my date text/field would work on "this layer".
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
No, a watermark is content. Plain, static text and graphics. Just like the other content on your page. Interactive form fields are a different thing. If you want data on the form that updates automatically then you will need to use an interactive form field.

Now if you want to get into the details, watermark content is attached to what's called an OCG, an Optional Content Group. OCGs are a way of marking, or grouping content like text and graphics into what is typically refered to as a Layer. OCGs can be turned on and off from JavaScript. Anything that is attached to an OCG is displayed when it is On, and not displayed when it is off.

Inteactive form fieds can be attached to an OCG. But this is a feature that can only be setup through a custom plug-in. It is not something that is availible in Acrobat's watermark feature. So don't even think about it. Watermarks are static content.

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

Benjamin
Registered: Nov 10 2009
Posts: 13
Last thing on this... Looks I'll need to create these as form fields.
I need the second field called todays date to be a form field because it changes depending on the date,
the document is opened by the end user.

I just need a way to add these fields to all pages in PDF document. Not to good with javascript here.
Some help would be appreicated. I know I'll need something like a loop or if statement to add the fields to each and every page of the entire PDF, as a watermark is out of the question, since I can't have it "change dynamically" -that is without getting over my head here.



Quote:
//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();
Quote:
var f = this.addField("message", "text", 0, [94, 32, 418, 7.5]);
f.textSize = 18;
f.textColor = color.red;
f.textFont = font.Helv;
f.value = "Printed Document Only Valid This Date";

// And so the user can't edit the text
f.readOnly = true;

var g = this.addField("todaysdate", "text", 0, [418, 32, 520, 7.5]);
g.textSize = 18;
g.textColor = color.red;
g.textFont = font.Helv;
g.value = "Date";

// And so the user can't edit the text
g.readOnly = true;
Well It looks like I solved it...
Just have to get use to this Java syntax....

Quote:
for (var i = 0; i < this.numPages; i++)var f = this.addField("message", "text", i, [94, 32, 418, 7.5]);
f.textSize = 18;
f.textColor = color.red;
f.textFont = font.Helv;
f.value = "Printed Document Only Valid This Date";

// And so the user can't edit the text
f.readOnly = true;

var g = this.addField("todaysdate", "text", i, [418, 32, 520, 7.5]);
g.textSize = 18;
g.textColor = color.red;
g.textFont = font.Helv;
g.value = "Date";

// And so the user can't edit the text
g.readOnly = true;
Benjamin
Registered: Nov 10 2009
Posts: 13
So now I can't figure out how to get this into the PDF File, via addscript method.... here's my first try..

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);
Okay... answered my own question again!

See answer to this post at:
http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=22942
Titled: "AddScript Method... need help on syntax here:"
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Great work so far!! Looks like you've got a good Batch Script for adding fields to the form. Assuming of course that the page size and field location is always the same. You might want to look at this article:
http://www.acrobatusers.com/tutorials/2006/page_bounds

Good job figuring out the "code in string" issues as well. However, since this is a document level script and it's only run once when the document is opened, it can be a lot simpler. This is all you really need for the script.
var cScriptCode = "//Get System Date and Populate Field called todaysdate\n" +"this.getField('todaysdate').value = util.printd('mm/dd/yyyy', new Date());";

The function is only necessary if you are going to be calling the code from more than one location. And the "bAlreadyOpened" is not necessary since this code is only run once when the PDF is opened.

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