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

JavaScript Code Issue: Unable to Attach CSV File to Email Using Adobe "Mail Doc" Feature

New Here ,
Apr 25, 2023 Apr 25, 2023

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,

TOPICS
JavaScript , PDF forms
1.7K
Translate
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 ,
Apr 25, 2023 Apr 25, 2023

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).

Translate
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 ,
Apr 25, 2023 Apr 25, 2023
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

 

Translate
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 ,
Apr 25, 2023 Apr 25, 2023

The mailDoc method doesn't have a cPath or a cURL parameters.

Translate
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 ,
Apr 25, 2023 Apr 25, 2023
LATEST

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/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Apr 25, 2023 Apr 25, 2023

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.

Translate
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