简体   繁体   中英

Executing javascript on save button in acrobat pro dc

I have this code which works wonderful in the console window:

var v = this.getField("count").valueAsString;
this.getField("count").value = util.printf("%06d", (v++));
this.saveAs("/Samouz HD/Users/Samouz/Documents/DGReports/Temp/" + (v++) + ".pdf")

So basically I have a reference number field in my form, I get that reference number and I want the file to save (as a duplicate) using that reference number.

And also to update to the next sequential number after the file is saved. I'd like to be able to run this with each 'save' of the pdf.

The saveAs method can only be executed during a batch or console event. In order to run it from a button, you'd need to create a trusted function and then call that function from the button. However, trusted functions can only be run when Acrobat loads so you'd need to have them installed on the recipient's hard drive prior to opening your file. See the link below for further documentation on Privileged versus non-privileged context in the Adobe viewers.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJSPreface%2FPrivileged_versus_non-privileged_context1.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM