Copy link to clipboard
Copied
Hi Guys,
I really need some expertise. I have developed a PDF Template with a button "SEND", the purpose of this button is to send the entire template (PDF) to a certain email and a certain CC mail. This is no problem to compute in adobe x pro. But, I also want to incorporate subject area in the mail. This subject area must refer to a specific textbox in the template.
Example:
Mailto: "Test@test.com"
Cc: "test2@test.com"
Subject Test9010 (Generate from the entered data in the template).
Does anyone have a suitable solutions? I have almost searched the entire google and forums for solutions.
Thanks in advance,
Good catch. Yes, "subject" should not be used because it interferes with an old property of the 'Doc" object (Acrobat DC SDK Documentation - Doc.subject())
Just rename all instances of the variable "subject" to "theSubject" and you should be OK:
Copy link to clipboard
Copied
That requires using a script. See here for more details: https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address
Copy link to clipboard
Copied
I have already tried this link, but I still have problems.
Do you know how to make it?
Copy link to clipboard
Copied
Please provide the script you've tried to use. What exactly happens? Are you getting errors? You may want to check the JavaScript console (Ctrl-J or Cmd-J) for errors.
Copy link to clipboard
Copied
I have tried:
In url:mailto:[emailaddress]?subject=
and as javaScript I have tried:
this.mailDoc(true, "test@test.com",
"test2@test.com");
But I don't know have to include the subject area which must be depend of one textboxes in the form.
Copy link to clipboard
Copied
Look at the documentation for Doc.mailDoc():
Acrobat DC SDK Documentation - Doc.mailDoc()
The subject needs to be passed in via a parameter to the function call. There is one example in the documentation that demonstrates that:
this.mailDoc({
bUI: false,
cTo: "apstory@example.com",
cCC: "dpsmith@example.com",
cSubject: "The Latest News",cMsg: "A.P., attached is my latest news story in PDF."
});
To add a subject that depends on some other information in your form, you will have to use a variable:
var subject = "no subject specified";
if (this.getField("CheckBox").value == "Off") {
subject = "this is one subject";
}
else {
subject = "this is another subject";
}
this.mailDoc({
bUI: false,
cTo: "apstory@example.com",
cCC: "dpsmith@example.com",
cSubject: subject,cMsg: "A.P., attached is my latest news story in PDF."
});
Copy link to clipboard
Copied
var subject ="no subject specified";
if (this.getField ("Text2").value=="Off"){
subject="This is one subject";}
this.mailDoc({
bUI: false,
cTo: "test@test.com",
cCC: "test2@test.com",
cSubject: subject,
cMsg: "Number"
});
There is no error, but the outlook do not open when I press my button "SEND".
The subject I want in the subject area in outlook is "Text2" in the pdf form. "Text2" is number that specify the pdf unique.
Do you have any suggestion how to solve this?
Thanks a lot so far.
Copy link to clipboard
Copied
I recommend you rename the "subject" variable to something else, first of
all.
Copy link to clipboard
Copied
I'm not getting it. What should replace it?
Copy link to clipboard
Copied
There is no need to rename the variable. "subject" is not a name that is used in the document or event object, so there is no conflict that could potentially cause the problem you are seeing. Your problem is caused by trying to change my code without a good understanding of what it tried to do. You cannot copy&paste things you find without understanding of what the code is doing. Do yourself a favor and learn about the core JavaScript language. Your code was testing to see if the field "Text2" contained the value "Off" - and only then would it try to send an email. My original code assumed that "CheckBox" was a checkbox field, and returned two values: "Off" when the checkbox was not selected, and something different for the selected state, and it would use one subject string in one case, and a different one in the other case.
The Field.value property for a checkbox is either "Off", or the specified expert value (the default is "Yes"), the same property for a text field is the string that was entered into the field. In that case, you don't have to use an "if" statement, you can assign the value directly to the "subject" variable (or even directly to the "cSubject" parameter when the function is called. Try the following, it will read the value of your text field, and will use it as the subject line in your email submission:
var subject = this.getField("Text2").value;
this.mailDoc({
bUI: false,
cTo: "test@test.com",
cCC: "test2@test.com",
cSubject: subject,
cMsg: "Number"
});
Copy link to clipboard
Copied
There is no need to rename the variable. "subject" is not a name that is used in the document or event object, so there is no conflict that could potentially cause the problem you are seeing.
You're wrong. There is an internal property of the Document object called "subject" (see p. 266 of the JavaScript for Acrobat API Reference, XI version), and even though it's no longer in use it still exists and should not be overwritten. Also, since it's a read-only property in Reader it might cause the script to fail there entirely, or produce the wrong results.
Copy link to clipboard
Copied
Good catch. Yes, "subject" should not be used because it interferes with an old property of the 'Doc" object (Acrobat DC SDK Documentation - Doc.subject())
Just rename all instances of the variable "subject" to "theSubject" and you should be OK:
Copy link to clipboard
Copied
Thanks a lot Karl Heniz! It works perfectly!
I'am quite new in this forum, is there any place I can rate your valuable your help?
Copy link to clipboard
Copied
You can click on the "Correct Answer" button below the reply that answered your question.
Copy link to clipboard
Copied
Hello - Do you know how to add 2 fields from the form into the subject line?
Copy link to clipboard
Copied
Following the example given above, use something like this:
var theSubject = this.getField("Text2").value + " " + this.getField("Text3").value;
Copy link to clipboard
Copied
thank you! I now have the request to add the words Product Order before the above code. I tried this but then only the words Product Order show up in the subject line.
var theSubject = "Product Order: " + this.getField("Account").value; this.getField("PO").valueAsString this.mailDoc({ bUI: false, cTo: "orders@Company.com", cSubject: theSubject, cMsg: "Please ensure that your account# and PO# are in the subject line." });
Copy link to clipboard
Copied
Use the "+" operator between the values of the fields you want to add, not a semi-colon. Like this:
var theSubject = "Product Order: " + this.getField("Account").valueAsString + this.getField("PO").valueAsString;
Copy link to clipboard
Copied
I tried this and only Product Order shows in the subject line... what is incorrect?
var theSubject = "Product Order" + this.getField("Account").value + " " + this.getField("PO").valueAsString
this.mailDoc({
bUI: false, cTo: "orders@company.com",
cSubject: theSubject,
cMsg: "Please ensure that your account# and PO# are in the subject line."
});
Copy link to clipboard
Copied
I'll need to see the file to help you further with this. As far as I can see it should include both values.
Copy link to clipboard
Copied
Thanks for your help! I won't be able to send the file.
Copy link to clipboard
Copied
I created a sample file with the same code and it works just fine. See: https://drive.google.com/file/d/1Q0HIda5IvmhCX6GDPxe_a3ckGGHOBXjQ/view?usp=sharing
Copy link to clipboard
Copied
Thank you. This will be helpful. I think the problem is that the java script in this form that was working yesterday isn't working today. Same form, nothing changed, now not working. Guess i need to solve that next.