Skip to main content
Participating Frequently
October 22, 2021
Answered

Duplicating form field with Javascript across multiple documents?

  • October 22, 2021
  • 2 replies
  • 4593 views

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

    This topic has been closed for replies.
    Correct answer try67

    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


    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;
    }

    2 replies

    try67
    Community Expert
    October 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...

    JulesG74Author
    Participating Frequently
    October 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 🙂

    try67
    Community Expert
    October 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();");
    Ged_Traynor
    Community Expert
    October 22, 2021

    Hi

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

    JulesG74Author
    Participating Frequently
    October 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