How to communicate with Acrobat from InDesign
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;
}