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

How to communicate with Acrobat from InDesign

Guru ,
Mar 04, 2010 Mar 04, 2010

Copy link to clipboard

Copied

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;
}

TOPICS
Scripting

Views

9.9K

Translate

Translate

Report

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
Guest
Jun 18, 2010 Jun 18, 2010

Copy link to clipboard

Copied

Hi Kasyan,

I have sent a indesign file to your mail ID.

Votes

Translate

Translate

Report

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
Guru ,
Jun 18, 2010 Jun 18, 2010

Copy link to clipboard

Copied

Muthuraj,

You say that you run this script manually in Acrobat:

var f = this.getField("Mail", "button");

f.setAction("MouseUp", "this.mailDoc(true);" );

But it gives me an error both in Acrobat 9 on Mac and 8 on PC:

TypeError: f has no properties

2:Console:Exec
Undefined

I checked getField method in Acrobat reference:

getField  -- Maps a Field object in the PDF document to a JavaScript variable.

Beginning with Acrobat 6.0, this method can return the Field object of an individual widget. For more information, see Field object.

Parameters -- cName -- The name of the field of interest.

Returns -- A Field object representing a form field in the PDF document.

As far as I understand, there should be 1 parameter instead of 2.

I run your script from post #21 -- it exported a pdf-file. Does this file contains the field you want to add the action to? What is the name of this field: "Mail" or "button"?

I am not an expert in Acrobat -- never worked with forms, fields, etc. Could you describe me in short how to do what the script does manually in Acrobat?

Kasyan

Votes

Translate

Translate

Report

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
Guest
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi Kasyan,

Following are the stpes to be done manually in a pdf to set action to attach with email. To do this we dont need any prior named field to set action. We can create this link whereever we want in pdf.

1. Open a pdf

2. Select the area with Link tool where you want to create link

3. In the Create Link popup window, select Custom Link and click Next

4. In Link Properties popup window go to the tab Actions. In that Select Action field, choose Execute a menu item and click Add. Select File > Attach to Email and click OK and OK to close the popup window.

Now you can see that particular action has been set for that linked area.

To automate this action in pdf, we need a field already available in pdf as the email image placement is not constant. The position may vary. So, I thought of creating a button in Indesign so that it would get converted as a field in pdf. In Acrobat we can identify a field and set action using Javascript.

In the Indesign file which I sent to you, you can see a button created with the name Email to generate a field called Email in pdf.

The script which I sent to you is working fine at my system (Acrobat 9 and Windows XP)

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

and Mail is the name of the field and button is the type of the field here. And the indesign file has the Email button and it get converted to a field in pdf.

Hope I am not confusing you much and I have answered your questions. Thanks for all your help on this.

Muthuraj. D

Votes

Translate

Translate

Report

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
Guest
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Kasyan,

Also, please try this code in Acrobat

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

Since the indesign has the button name as Email the field in pdf also get named with Email. Please update Mail with Email in the code and try again. Sorry, I updated this info in the full set of code in indesign and gave you the old code

Votes

Translate

Translate

Report

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
Guru ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Hi Muthuraj,

Here is the working script:

#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);

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);
    var f = myAcrobatDoc.getField("Mail");
    f.setAction("MouseUp", "this.mailDoc(true);");
    myAcrobatDoc.saveAs(myFilePath);
    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;
}

Your code didn't work because it had a couple of problems:

#1

var f =this.getField("Mail", "button");

should be

var f =myAcrobatDoc.getField("Mail");

Since your code is inside the function, this keyword doesn't reference to the active document, probably it references to the object calling the function instead.

Where did you see the 2nd parameter for getField method in the acrobat reference? I guess that acrobat just ignores it.

#2

myAcrobatDoc.closeDoc(false );

False means that the user will be prompted to save the document if it has been modified.

True means that the document will be closed silently without saving

So we should save it to the same location and close it without prompt:

myAcrobatDoc.saveAs(myFilePath);

myAcrobatDoc.closeDoc(true);

But Acrobat has a pitfall -- so called Save path, which means that you can't run the script if your document is in a system critical folder -- e.g. root, windows or system directory.

For example, the script works if your file is here:

C:\Test\EmailIcon.indd

and doesn't works if it's here:

C:\ EmailIcon.indd

Regards,

Kasyan

Votes

Translate

Translate

Report

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
Guest
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Hi Kasyan,

Thanks for all your support and explanatory answer.

I tried the given code and it is working perfectly till creating a pdf and not doing it's part in Acrobat. It just generate a pdf. I think it is still not communicating with Acrobat. I can say this as we have included a code to close the document (myAcrobatDoc.closeDoc(true); ) after done everything, but it is not happening. Please help me Kasyan. It would be so great if you make this script work in Acrobat as well. Again, thanks a lot for your continueous support.

Regards,

Muthuraj. D

Votes

Translate

Translate

Report

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
Guru ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Hi Muthuraj,

Believe it or not, but this script worked for me on InDesign CS3 + Acrobat 8.0

According to Acrobat API reference (version 9.1), methods and their parameters used in the script haven't changed since version 8, so I think it should work for you too. However I can't check it since I don't have windows version of CS4 (PC computers available to me are too old). On Mac it doesn't work.

Currently the script doesn't handle any errors that might occur in the acrobat part, so you should either test the script being sent from InDesign to Acrobat yourself, or add an error handler.

I suggest you to do the following test:

1) Add this line

...

bt.body = myScript;

$.writeln(myScript);

bt.send();

...

and run the script from ESTK

2) Copy the script from ESTK console -- don’t include true (or false) at the end of the last line -- and paste it into Acrobat's console and run the script. See if any error occurs.

Kasyan

Votes

Translate

Translate

Report

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
Guest
Jul 06, 2010 Jul 06, 2010

Copy link to clipboard

Copied

Hi Kasyan,

Sorry, I was not well for a week and I could not access to the internet. I tried the following methods however it still not happening in Acrobat. It generates the pdf and stops.

I tried running it in Acrobat console and it did not give any error.

Please advise. Thanks.

Votes

Translate

Translate

Report

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
Guru ,
Jul 07, 2010 Jul 07, 2010

Copy link to clipboard

Copied

LATEST

Try to add error handler to the BridgeTalk message:

bt.body = myScript;

bt.onError = function(resObj)
{
     alert(resObj.body);
     exit();
}

bt.send();

Kasyan

Votes

Translate

Translate

Report

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