Copy link to clipboard
Copied
Hello Adobe Community,
I am currently working on a JavaScript code to retrieve all the fields and their corresponding values from a PDF form, convert them into a CSV file, and then attach the CSV file to an email using the "mail doc" feature. However, when I open the email, I am unable to see the attached CSV file, and in some cases, I am encountering an error message that says "security prevents access to this property or method."
I would appreciate any guidance or solutions from the community regarding this issue. Thank you in advance for your help.
Best regards,
Copy link to clipboard
Copied
Please share the specific code - actually both, the code that gets the error message, and the code that doesn't, and seems to send the file. You needn't give all the details of how you fill in the CSV (but leave in the open/creation/closing/saving/whatever).
Copy link to clipboard
Copied
var fieldKeys = [];
var fieldValues = [];
for (var i = 0; i < this.numFields; i++) {
var field = this.getField(this.getNthFieldName(i));
fieldKeys.push(field.name);
fieldValues.push(field.value);
}
var csvContent = fieldKeys.join(',') + '\n' + fieldValues.join(',');
this.createDataObject('output.csv', csvContent);
var attachment = this.getDataObjectContents('output.csv');
var email = "recipient@example.com";
var subject = "CSV file attachment";
var message = "Please find attached the CSV file.";
var mimeType = "text/csv";
var fileName = "output.csv";
this.mailDoc({bUI: true, cTo: email, cSubject: subject, cMsg: message, oAttach: attachment, cPath: mimeType, cSubmitAs: "PDF", cURL: fileName});i have created this script
Copy link to clipboard
Copied
The mailDoc method doesn't have a cPath or a cURL parameters.
Copy link to clipboard
Copied
Or an "oAttach" argument.
As try67 said, it can't be done with a script, because the feature simply doesn't exist in the Acrobat JavaScript model. You can however email the data as a tab delimited, by using the doc.submitForm function, using an email address as the URL.
Here's a couple of articles on the topic.
https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address/
https://acrobatusers.com/tutorials/submitting-data/
Copy link to clipboard
Copied
This is not possible with a script. It can only attach the PDF document itself to an email it generates.
The CSV file can be attached to the PDF, though.