Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Duplicating form field with Javascript across multiple documents?

Community Beginner ,
Oct 22, 2021 Oct 22, 2021

Hi there, I have spent far too much time googling this and trying different things such as stamps but would like to know if there is a simple way to save a form field to use on multiple docs (I know how to duplicate across pages but not across docs!).

 

I add a form field to say "This document was printed on <today's date and time>"

 

Where today's date and time is a javascript that works it out the current date and time.  I also add the same script to "will print" and "did print" to ensure it will give the most current on opening and printing.

 

It is a monotonous task to do when you have to add to hundreds of documents and I would like to know if there is a quick way to create the form and then apply it to as many docs as you need to (I can do it with applying a saved watermark to all open docs, so hoping I can do this too)

It would speed up my friday work no end!

 

Thanks for any help

4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Oct 28, 2021 Oct 28, 2021

You can use this code to add the field, and all of the scripts used for it:

 

var f = this.addField("Today", "text", 0, [222.6179962158203,775.823974609375,372.6180114746094,753.823974609375]);
f.readonly = true;
this.addScript("Today", "function updateToday() {var f = this.getField(\"Today\");f.value = \"Document printed on \" + util.printd(\"dd/mmm/yyyy HH:MM\", new Date());} updateToday();");
this.setAction("WillPrint", "updateToday();");
this.setAction("DidPrint", "updateToday();");

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2021 Nov 01, 2021

Do you want all the fields to be identical copies of each other?

If so, place the addField command in a a loop that iterates over all the page numbers, like this:

 

for (var p=0; p<this.numPages; p++) {
	var f = this.addField("Today", "text", p, [222.6179962158203,775.823974609375,372.6180114746094,753.823974609375]);
	f.readonly = true;
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2021 Oct 22, 2021

Hi

Can you tell us which Adobe application you're using so we can move the thread to the correct forum

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2021 Oct 22, 2021

Hi Sorry Yes Acrobat Pro DC, thank you

 

You need to ask program questions in the forum for the program you are using
To ask in the forum for your program please start at https://community.adobe.com/
Moving from Using the Community (which is about the forums) to the correct forum... Mod

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2021 Oct 22, 2021

Yes, this can be done in Acrobat Pro using an Action that executes a script that adds the field and set the document actions. Where on the page do you want the field to appear, and what should it look like? If you could share a sample page with the field it might be easier...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 28, 2021 Oct 28, 2021

Hi there  I have attached a PDF with the field applied at the top of the page (which is where I put it).  (I have left the field so that it isn't read only in case you need to do anything).

 

Thank you so much for any help you can provide 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2021 Oct 28, 2021

You can use this code to add the field, and all of the scripts used for it:

 

var f = this.addField("Today", "text", 0, [222.6179962158203,775.823974609375,372.6180114746094,753.823974609375]);
f.readonly = true;
this.addScript("Today", "function updateToday() {var f = this.getField(\"Today\");f.value = \"Document printed on \" + util.printd(\"dd/mmm/yyyy HH:MM\", new Date());} updateToday();");
this.setAction("WillPrint", "updateToday();");
this.setAction("DidPrint", "updateToday();");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 29, 2021 Oct 29, 2021

Thank you, please can you let me know what I need to do with this script? Is it in Action Wizard - where do I put it to make it work?  

 

Thanks so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2021 Oct 29, 2021

Yes, in the Action Wizard. Create a new Action, add to it an Execute JavaScript command (make sure to untick the "Prompt Changes" check-box!) with this code, and then add a Save command after it, and then run the Action on your files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2021 Nov 01, 2021

That is great thank you so much it will save me so much time.   Just one more question, if I need the positioning of the text box to be moved what do I do to the script to move it? 

 

I'm assuming it has something to do with coordinates or something from the long number string in the script.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2021 Nov 01, 2021

Guessing I take it from here

JulesG74_0-1635760513663.pngexpand image

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2021 Nov 01, 2021

I changed the unit of measurement to points and tried replacing the numbers in your script with the numbers in the boxes, but it didn't work, probably because I don't know how to write scripts properly LOL

 

JulesG74_0-1635761065990.pngexpand image

 

I am so very close, almost there, I also also need to add to the script to duplicate across all pages can that be done, otherwise I think it will mean I will still have to open up each document to durplicate the text field.,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2021 Nov 01, 2021

Yes, you're almost there.

The coordinates need to be in the following order (using the Points units):

[left, top, right, bottom]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2021 Nov 01, 2021

Thank you, and what do I need to add to the script to duplicate the text box across all pages 🙂

 

Sorry I don't ask for much do I LOL

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2021 Nov 01, 2021

Do you want all the fields to be identical copies of each other?

If so, place the addField command in a a loop that iterates over all the page numbers, like this:

 

for (var p=0; p<this.numPages; p++) {
	var f = this.addField("Today", "text", p, [222.6179962158203,775.823974609375,372.6180114746094,753.823974609375]);
	f.readonly = true;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2021 Nov 01, 2021
LATEST

Yes I do, thank you so much for your help, a long and monotonous task made much quicker.  Really appreciated 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines