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

Add button in VBA

New Here ,
Feb 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

I am struggling to add a button using IAC code.

 

Using these references I can't find all the properties to set for a button.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/interapp
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref

I did just find

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsdevguide/JS_Dev_AcrobatForms.html

but still having issues.

With this code snip, the button is added, but does nothing.

btn = jso.addField("Submit_btn","button", 0, aBtnRect)

'properties
btn.buttonSetCaption("Submit Form")
btn.borderStyle = "border.b" 'beveled edges. but what I want is rounded corners.
btn.textColor = "color.black" 'error <<<<<<<<<<
btn.lineWidth = 1 'Thin Border
btn.setAction("MouseUp", "mailto:test@abc.com")

I get an error on textColor. 

 

Also a problem setting button action.

Bill2801679328v4_0-1676240424101.png

The actions window says 'Run a javascript'.  But if I add a button in the UI, both the Actions window and Select Action field say Submit a form.  The button added by code does not do anything.

TOPICS
JavaScript , PDF forms

Views

899

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
New Here ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

I was not able to use the Color object, but could define the color array as all character.

dim fillColor[0..4] as C
fillColor[0] = "RGB"
fillColor[1] = "0.887"
fillColor[2] = "0.734"
fillColor[3] = "0.976"
btn.fillColor = fillColor

 

But I still have the second problem of the button action not sending an email.

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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

You can use the Javascript method submitForm.

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 ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

To be clear, you can ONLY add a button with a JavaScript action. So you now need to write the JavaScript action for your button. "mailto:test@abc.com" is not (in itself) valid JavaScript. Beware especially of the need to escape quotes-in-quotes.

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
Community Expert ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

That's because color.black and border.b are not strings, but objects. color.black is an array, as you saw, and border.b is actually a string, namely "beveled". So if you can't specify them directly you have to use what they represent.

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
New Here ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

LATEST

I agree try67.  That was one of MANY tests.  The default Color object seems limited so I finally got this working.

Dim textColor[0..4] as C
textColor[0] = "RGB"
textColor[1] = "0"
textColor[2] = "0"
textColor[3] = "1"
btn.textColor = textColor

even though the js array wants the colors as numeric, this gets interpreted correctly.

 

Test, I got the email working with this code adapted from a sample I found.  Thanks.

jstext2 = <<%str%
var cSubject = "Email subject line";
var cBody = "body of message";
var cEmailURL = "mailto:test@abc.com?subject=" + cSubject + "&body=" + cBody;
this.submitForm({cURL: encodeURI(cEmailURL), cSubmitAs:"PDF"});
%str%
btn.setAction("MouseUp", jstext2)

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