Skip to main content
Kasyan Servetsky
Legend
March 4, 2010
Question

How to communicate with Acrobat from InDesign

  • March 4, 2010
  • 3 replies
  • 11288 views

Yesterday Loic asked me for an example of a script that would send the pdf file by mail.

Today I made it and decided to post it here on the forum — may be this will be interesting to somebody.

It exports the frontmost document to pdf file using [Smallest File Size] preset, then opens it in acrobat, sends it in the attachment to this e-mail address: someone@somewhere.com (please change it) and finally closes the file.

I tested it on CS3 for Windows, but I can't send e-mails from my Mac. Can anybody test it on Mac?

Kasyan

#target indesign
var myIndesignDoc = app.activeDocument;
var myParentFolder = myIndesignDoc.fullName.parent;
var myBaseName = GetFileNameOnly(myIndesignDoc.name);
var myFilePath = myParentFolder.absoluteURI + "/" + myBaseName + ".pdf";
var myFile= new File(myFilePath);
myIndesignDoc.exportFile( ExportFormat.pdfType, myFile, false, "[Smallest File Size]" );

var myScript = AcrobatScript.toString() + '\r';
myScript += 'AcrobatScript(\"' + myFilePath + '\");';
var bt = new BridgeTalk;
bt.target = "acrobat";
bt.body = myScript;
bt.send();

function AcrobatScript(myFilePath) {
     var myAcrobatDoc = app.openDoc(myFilePath);
     myAcrobatDoc.mailDoc({
          bUI: false, // don't show dialog box
          cTo: "someone@somewhere.com", // e-mail address
          cSubject: "This message was sent you by script", // subject line
          cMsg: "Here goes some message text."// message body
     });
     myAcrobatDoc.closeDoc( true );
}

function GetFileNameOnly(myFileName) {
     var myString = "";
     var myResult = myFileName.lastIndexOf(".");
     if (myResult == -1) {
          myString = myFileName;
     }
     else {
          myString = myFileName.substr(0, myResult);
     }
     return myString;
}

This topic has been closed for replies.

3 replies

June 17, 2010

Thanks Kasyan! you have done a great help to me. I have tried your script and it works fine till generating pdf. My requirement is little different. I have a field called "Email" in pdf and a action to set for that button to attach with email.

#target indesign
var myIndesignDoc = app.activeDocument;
var myParentFolder = myIndesignDoc.fullName.parent;
var myBaseName = GetFileNameOnly(myIndesignDoc.name);
var myFilePath = myParentFolder.absoluteURI + "/" + myBaseName + ".pdf";
var myFile= new File(myFilePath);

var mylayerText = myIndesignDoc.layers.item("Text")
var mylayerGraphics = myIndesignDoc.layers.item("Graphics")
var mylayerOnlinePdf = myIndesignDoc.layers.item("Online PDFs")
var mylayerTagline = myIndesignDoc.layers.item("Print tagline")

mylayerText.visible = true
mylayerGraphics.visible = true
mylayerOnlinePdf.visible = true
mylayerTagline.visible = false

var myPDFExportPreset = app.pdfExportPresets.item("EBLowRes");
app.activeDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);

//myIndesignDoc.exportFile( ExportFormat.pdfType, myFile, false, "[Smallest File Size]" );

var myScript = AcrobatScript.toString() + '\r';
myScript += 'AcrobatScript(\"' + myFilePath + '\");';
var bt = new BridgeTalk;
bt.target = "acrobat-9.0";
bt.body = myScript;
bt.send();

function AcrobatScript(myFilePath) {
     var myAcrobatDoc = app.openDoc(myFilePath);
//app.execMenuItem("Email");
  var f = myAcrobatDoc.getField("Email", "button");
  f.setAction("MouseUp", "myAcrobatDoc.mailDoc(true);" );
     //myAcrobatDoc.mailDoc({
        //  bUI: false, // don't show dialog box
         // cTo: "someone@somewhere.com", // e-mail address
          //cSubject: "This message was sent you by script", // subject line
          //cMsg: "Here goes some message text."// message body
     //});
     myAcrobatDoc.closeDoc( false );
}

function GetFileNameOnly(myFileName) {
     var myString = "";
     var myResult = myFileName.lastIndexOf(".");
     if (myResult == -1) {
          myString = myFileName;
     }
     else {
          myString = myFileName.substr(0, myResult);
     }
     return myString;
}


I tried this little modified code and it generates the pdf but does not set action for that particular button.

The code I am using in Acrobat to set action is

var f = this.getField("Mail", "button");
f.setAction("MouseUp", "this.mailDoc(true);" );

Rather than going to Acrobat and run this script manually is this possible to combine this action within Indesign script? 

Please help me.

Regards,

Muthuraj. D

Kasyan Servetsky
Legend
June 17, 2010

Rather than going to Acrobat and run this script manually is this possible to combine this action within Indesign script? 

if you're on Mac not , if on Windows -- most probably yes. Which version of InDesign do you use?

Kasyan

June 18, 2010

Hi Kasyan, Thanks for your quick reply.

I am using Windows, Indesign CS4 and Acrobat 9 Pro Extended. I hope I am lucky to get the solution

Peter Kahrel
Community Expert
Community Expert
March 13, 2010

Kasyan,

Thanks for sharing this useful script. However, I can't get it to work because apparently Acrobat doesn't like my email program. After the PDF is created and loaded in Acrobat, nothing happens. When I try to attach the PDF manually (File > Attach to Email), Acrobat says ""Acrobat is unable to connect to your email program." I've poked around in the preferences but can't seem to find any way to tell Acrobat what my email program is (Opera's mail client). Any idea?

Another thing: to construct the PDF name for the current document, could you not simply say the following?

myFilePath = String (myIndesignDoc.fullName).replace (/indd$/, "pdf");

Thanks,

Peter

Jongware
Community Expert
Community Expert
March 13, 2010

myFilePath = String (myIndesignDoc.fullName).replace (/indd$/, "pdf");

Kasyan is careful not to mess up a filename without its extension

Yours may be a bit better if you use this (untested!)

myFilePath = String (myIndesignDoc.fullName)+".indd";

myFilePath = String (myIndesignDoc.fullName).replace (/\.indd(\.indd)?$/, "pdf"); (oops)

myFilePath = myFilePath.replace (/\.indd(\.indd)?$/, "pdf");

to always make sure the original name ends with ".indd".

Peter Kahrel
Community Expert
Community Expert
March 13, 2010

> Kasyan is careful not to mess up a filename without its extension

Have you ever seen an InDesign file without .indd extension?

Peter

SuperMacGuy
Known Participant
March 4, 2010

I can't seem to make it work. It produces a PDF but then I don't see any activity or emailing it seems.

CS3 and Acro 8 and Acro 9

Kasyan Servetsky
Legend
March 13, 2010

I've found the reason why it doesn't work on Mac:  Acrobat is not a messaging-enabled application on Mac ( it is on Windows).

You can test it by running this line:

BridgeTalk.getSpecifier("acrobat");
==> acrobat-8.0 -- on Windows

==> null -- on Mac

or you can get the list of messaging-enabled application:

BridgeTalk.getTargets();

on Windows,  Acrobat is in the list:

acrobat,bridge,devicecentral,dreamweaver,estoolkit,illustrator,indesign,photoshop,stockphotos

but on Mac, it's missing