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

Form Updates: How do you copy/paste all JavaScript from one pdf to another?

Engaged ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

I feel like I have asked this question before on the old acrobatusers.com forum but can't seem to find it...

Anyway, I create a lot of forms and use a lot of JavaScript in them. The form designs/features/functions are updated quite regularly, and I'd like to find out a way to make the process of adding the scripting back in not so tedious.

I can't seem to just copy and paste in JavaScript Panel > All JavaScripts or JavaScript Panel > Document Actions > Edit All

Is there a script or another way to do this or am I stuck with recreating document scripts and pasting scripts in each individual interactive object?

A little about my workflow:

I use InDesign CC to create the form layouts and fields and try to do as much in InDesign as possible. There are a few caveats and possibilities of issues between the two programs, but more often than not, I can manage around those issues.

Prior to InDesign having the capabilities of creating forms, I used to design the form in InDesign, export then lay out all of the fields by hand, which was again tedious. When I made updates to the design, I would replace the background in the PDF and move the fields around.

TOPICS
Acrobat SDK and JavaScript

Views

2.3K

Translate

Translate

Report

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

correct answers 1 Correct answer

Engaged , Jan 20, 2020 Jan 20, 2020

I learned the answer to this issue about two or three years ago.

It's to create a master script using the setAction Field Method as defined in the SDK. For document level scripts, I use the addScript method.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#rhhlterm=form%20field%20events&rhsyns=%20&t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_methods.htm

Once I create a master script, I'm able to make updates and then just run the script in the console. I put each string i

...

Votes

Translate

Translate
Community Expert ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

Use your old workflow.

Votes

Translate

Translate

Report

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
LEGEND ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

One can take of copy of the form you want the scripts and form fields from and replace the original page with the new page.

You can insert the old form into the new form and delete the old form, this will add all the document level scripts.

One can use and FDF to import document level scripts and other scripts.

Votes

Translate

Translate

Report

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
Engaged ,
May 19, 2016 May 19, 2016

Copy link to clipboard

Copied

Thank you gkaiseril​ for your suggestions. I've done both of your first two suggestions before in other forms.

I'm really looking for a scripted solution of some sort, if possible.

The issue with #1 is replacing pages will only bring over the layout graphics and nothing interactive on the new page, so that's not viable unless the update was something getting omitted.

#2 is more viable and could work, but more work to me than just adding the JavaScript actions. Again, it would add all the doc level scripts, but I'd be stuck with having to align all of the form fields to the "new" form as it won't merge the mouse-up script for the individual fields, just creates a new instance of it.

#3: I've done a little with FDF data. The issue with a lot of the forms I do is that for some reason, FDF data will destroy my button icons, so I typically use it in text only forms. I'm not familiar with how to import scripts with it, however.

Votes

Translate

Translate

Report

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
Engaged ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

LATEST

I learned the answer to this issue about two or three years ago.

It's to create a master script using the setAction Field Method as defined in the SDK. For document level scripts, I use the addScript method.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#rhhlterm=form%20field%2...

Once I create a master script, I'm able to make updates and then just run the script in the console. I put each string in single quotes and concatenate with the + symbol. For scripts that I want a carriage return, I put \n before the ending single quote.

Here's an example:

//set buttons to read only, text to uppercase, and Title text color
	for (var i = 0; i < this.numFields; i++) {
		var fname = this.getNthFieldName(i);
		var f = this.getField(fname);
		var readoBtn = /(hover.+?\d+|blank\d+|click.\d+|cont_hide|hide\d+|hf\d+)/;
		var sTitle = /title.+/;
			if(f.name.match(readoBtn)) {
				f.readonly = true;
			}
		if(f.type === "text"|f.type === "combobox") {
			f.setAction("Keystroke", "event.change = event.change.toUpperCase();");
			/**f.textFont = "MyriadPro-Regular";**/
			if(f.name.match(sTitle)) {
				f.textColor =  ["RGB", (68/255), (158/255), (72/255)];
			}
			if(f.type === "combobox") {
				f.commitOnSelChange = true;
			}
		}
	}

 

Votes

Translate

Translate

Report

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