Skip to main content
May 19, 2020
Answered

Acrobat DC Javascript custom dialogue help

  • May 19, 2020
  • 3 replies
  • 1900 views
  • I am a complete newbie to JavaScript and this is my first post. With the help of various snippets of script I have found on the web and Thom Parker's book "all about pdf stamps" I have created a custom dialogue to populate several text fields and tick boxes of a dynamic stamp. The stamp works well but it could be better. I would like the input fields on the custom dialogue to display default values rather than blank white space. I can get one field to display as I would like, but only the last of 7 fields does this. If I copy what I did in field 7 to the others it doesn't work for the others but field 7 does work. Can you help? I have 7 lines like this:
  • strField1: "", 
  • initialize: function(dialog) {
  • dialog.load({"fld1":this.strField1});
  • },
  • These lines are repeated with strField1 and fld1 replaced by  strField2 to strField7 and fld2 to fld7 followed by the following script:
  • commit:function(dialog) {
  • var data=dialog.store();
  • this.strField1=data["fld1"];
  • Again this is repeated for the other fields as before.
  • I changed strField7:"", to strField7:"something else", and it defaults to "something else" instead of white space and the stamp works whether the custom dialogue default value is left or it is typed over. But it only works with this last field. If I do exactly the same thing with the others I still get the blank white input box but no default. I hope this makes sense and somebody can help me with this.
This topic has been closed for replies.
Correct answer try67

You've over-complicated the code. Simply use this as the initialize function:

 

 

    initialize: function(dialog) {
        dialog.load({
			"fld1":"1",
			"fld2":"2",
			"fld3":"3",
			"fld4":"4",
			"fld5":"5",
			"fld6":"6",
			"fld7":"7"
		});
    },

 

3 replies

May 19, 2020
Thank you Thom. Sometimes I find it hard to work things out for myself. I wouldn't have made it this far without your book and the help of both you and Try67. I greatly appreciate your help.
Thom Parker
Community Expert
Community Expert
May 19, 2020

Thanks, Glad to help

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
May 19, 2020

You'll find a drag and drop Dialog editor, and some tutorial vidoes, here:

https://www.pdfscripting.com/public/ACRODIALOGS-OVERVIEW.cfm 

 

If you have questions about these things, you should email or message me.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 19, 2020

You've over-complicated the code. Simply use this as the initialize function:

 

 

    initialize: function(dialog) {
        dialog.load({
			"fld1":"1",
			"fld2":"2",
			"fld3":"3",
			"fld4":"4",
			"fld5":"5",
			"fld6":"6",
			"fld7":"7"
		});
    },

 

May 19, 2020

Try67 I cannot thank you enough. I am a complete novice to JavaScript and do not fully understand it as you can tell. I am surprised I got this far before getting stuck. But I have seen the help you have given others. The speed with which you replied was phenomenal and the solution spot on. Many thanks.

try67
Community Expert
Community Expert
May 19, 2020

Don't feel bad. Dialogs are one of the most complicated things one can do in Acrobat JS...