These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Acrobat Closes unexpectedly?

TecNik
Registered: Feb 25 2008
Posts: 17

Hi there,

I've been playing around with the code for adding a security policy to a pdf which works fine.

I've tried to take the script a few stages further so that the security policy is added, the pdf is saved, and then it is attached to an email however there's a slight niggle. The code executes ok and the email is generated with the password protected pdf. I'd also put in something that closes the pdf in Acrobat but instead of just closing the pdf it also quits Acrobat?

This is also the same for the version that just adds the security policy.

Please can someone point me in the right direction?

Thanks in advance,

Nick

EDIT - I've tried this.closeDoc(); instead of app.execMenuItem("Close"); and I still get the same result, Acrobat adds the security policy, closes the doc, but then Acrobat quits?

Any help would be appreciated.

Thanks,

Nick

//**********************************************************************************
//**********************************************************************************
//
// Example Folder Level JavaScript File for the JavaScript Corner article:
// "Applying PDF Security with Acrobat JavaScript" at www.acrobatusers.com
//
// By Thom Parker, WindJack Solutions, Inc.
// Copyright 2007 by WindJack Solutions, Inc.
//
// Copy this file into the Acrobat Professional 7.0 or later JavaScript Folder
//
// This file places a toolbar button on Acrobat's Add-Ins Toolbar.
//
// To use this Toolbar Button you MUST have a security Policy named "MySecurityPol"
//
//**********************************************************************************

//
// This script was created by AcroButtons from Windjack Solutions, www.windjack.com
// Do not modify the code inbetween the AcroButtons Tags
// Moving or changing tag positions can compromise AcroButtons' ability to handle
// this file
// Place Extra-AcroButton Code in the following "Code Above" Section
//

//
var DoApplyMySecurity = app.trustedFunction(
function()
{
var oMyPolicy = null;
app.beginPriv();
// First, Get the ID of My Security Policy
var aPols = security.getSecurityPolicies()
for(var i=0;i

//
var strData7ApplyMySecurity =
"0080808000808080008080800080808000808080FFB4AEA3FFCCB68BFF9E7530FF92630EFFA88220" +
"FF92630EFF9E7530FFCCB68BFFB4AEA3008080800080808000808080008080800080808000808080" +
"0080808000808080008080800080808000808080FF9E7325FF845104FFDCCD4EFFCFB83DFFA77F1A" +
"FFCFB83DFFDCCD4EFF845104FF9E7325008080800080808000808080008080800080808000808080" +
"00808080008080800080808000808080FFAEA697FF824E03FFDBC84CFF9F7515FF804D04FF976915" +
"FF845106FF9F7515FFDBC84CFF824E03FFAEA6970080808000808080008080800080808000808080" +
"00808080008080800080808000808080FFA59A87FF92620BFFBFA030FF8F5F0EFFECE2CB00808080" +
"FFECE2CBFF8F5F0EFFBFA030FF92620BFFA59A870080808000808080008080800080808000808080" +
"00808080008080800080808000808080FF9E9180FFC5A732FF9C7014FFC2A3630080808000808080" +
"00808080FFC2A363FF9C7014FFC5A732FF9E91800080808000808080008080800080808000808080" +
"00808080008080800080808000808080FF9D8F80FFC7AB36FF7E4901008080800080808000808080" +
"0080808000808080FF7E4901FFC7AB36FF9D8F800080808000808080008080800080808000808080" +
"00808080008080800080808000808080FF9D8F80FFC7AB35FF7E4901008080800080808000808080" +
"0080808000808080FF7E4901FFC7AB35FF9D8F800080808000808080008080800080808000808080" +
"00808080008080800080808000808080FF9D8F80FFC7AB35FF7E4901008080800080808000808080" +
"0080808000808080FF7E4901FFC7AB35FF9D8F800080808000808080008080800080808000808080" +
"00808080008080800080808000808080FF9D8F80FFC4A733FF7C480100808080FFF9F7F2FFF9F7F2" +
"FFF9F7F200808080FF7C4801FFC4A733FF9D8F800080808000808080008080800080808000808080" +
"0080808000808080FFADA492FFB8983BFFA98423FFA67E1EFFA57C1CFFA37818FFA17514FF9F6F0F" +
"FF9B6A0AFF996607FF976205FF956003FF925B01FFA87A29FFACA392008080800080808000808080" +
"0080808000808080FF764000FFE1CE4EFFF9F060FFF2E14EFFECD542FFE6CA36FFE1BF2CFFD9AD1E" +
"FFD19E14FFCB940FFFC68C0AFFC38506FFBC7B02FFA36300FF764000008080800080808000808080" +
"0080808000808080FF764000FFE3D14FFFF3E857FFE9D237FFE3C628FFDEB71AFFD7A50FFFCB8B06" +
"FFC47402FFBF6401FFB75700FFB14A00FFAC3900FF973400FF764000008080800080808000808080" +
"0080808000808080FF764000FFE1CD4BFFF2E356FFE8D247FFE3CA3DFFDFBF33FFDBB72BFFD2A81D" +
"FFCA9711FFC48A0AFFBF7E05FFB97102FFB46000FF9E4D00FF764000008080800080808000808080" +
"0080808000808080FF764000FFDFCA48FFEFDF4FFFE5C830FFE1B921FFD9A916FFD2990CFFC67E04" +
"FFBF6A02FFB96001FFB45500FFB04B00FFAB4000FF9A3C00FF764000008080800080808000808080" +
"0080808000808080FF764000FFDCC543FFECD949FFE3C433FFDCB928FFD7AC1EFFD29E15FFC88C0D" +
"FFC07906FFBB6E03FFB76301FFB25800FFAE4D00FF9B4500FF764000008080800080808000808080" +
"0080808000808080FF764000FFDBC23FFFE9D243FFE1C031FFDBB526FFD4AB1DFFCF9F15FFC88F0C" +
"FFBF7A05FFB96B02FFB35C00FFAD4F00FFAB3F00FF993C00FF764000008080800080808000808080" +
"0080808000808080FF764000FFD9C03CFFE7CF3EFFDCB928FFD8AB1DFFD19C13FFCB8D0DFFC17805" +
"FFB96A03FFB76201FFB35C00FFB05700FFB15700FF9E4D00FF764000008080800080808000808080" +
"0080808000808080FF764000FFC8A92DFFE4C839FFDCB726FFD7A91BFFCF9C12FFCA8D0BFFC17A05" +
"FFB96401FFB45400FFAD4700FFA93D00FFA73300FF953300FF764000008080800080808000808080" +
"0080808000808080FFC8AC6DFF9E6E0FFFA97B12FFA4750FFFA3720BFFA06E09FF9F6C06FF9B6703" +
"FF996201FF975E00FF965900FF955700FF945500FF8D4E00FFC4A361008080800080808000808080" +
"008080800080808000808080FFB89652FF764000FF764000FF764000FF764000FF764000FF764000" +
"FF764000FF764000FF764000FF764000FF764000FFBF9E5600808080008080800080808000808080";
//

// Icon Generic Stream Object
//
var oIconApplyMySecurity = oIconApplyMySecurity = {count: 0, width: 20, height: 20,
read: function(nBytes){return strData7ApplyMySecurity.slice(this.count, this.count += nBytes);}};
//}
//

//
var oButObjApplyMySecurity =
{cName: "ApplyMySecurity",
cExec: "DoApplyMySecurity()",
cEnable: "event.rc = (app.doc != null)",
cLabel: "TPS - Security and Mail",
cTooltext: "Add XXX password, Save, Close and create new email",
oIcon: oIconApplyMySecurity
};
//

//
try
{
app.addToolButton(oButObjApplyMySecurity);
}catch(e){console.println(e);}
//

//

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I believe that these are the three lines you added
            app.execMenuItem("Save"); app.execMenuItem("AcroSendMail:SendMail"); app.execMenuItem("Close");

First, all three lines are outside the if/else statment. I think you probably want to have them inside, so that they are only run when there is not an error. You'll need to put them inside curly braces after the else.

Next, it was very clever to use menu items to run the functions you want, save, email, and close. However, in Acrobat JavaScript, menu item execution is non-blocking. The script engine simply passes off the menu item name to Acrobat and moves on. This is the equivelent of clicking these three menu items with the mouse really fast one right after the other. In fact, clicking them faster than is humanly possible. Especially since the email menu item displays the email client UI. So this is the source of the problem. Acrobat is choking and dying on performing conflicting operations all at once.

Instead, use the JavaScript commands for these operation.

this.saveAs(...)
this.mailDoc(...)
this.closeDoc(...)


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

TecNik
Registered: Feb 25 2008
Posts: 17
Hi Thom,

Thank you for your reply and taking the time to help with my query.

I was about to post something I'd found that seemed to solve the problem:-

http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=15227

app.setTimeOut("this.closeDoc(false);",100);

This worked however having read your reply I guess it isn't the correct solution. I've two versions of the script, one that applies the policy, saves the doc and closes it, and the other that does the same and attaches the pdf to a mail.

I've done quite a bit with Applescript and having experienced certain things with that I can see what you mean about firing off the app.execMenuItem one after another.

I'm just in the process of trying implement your solution.

Thanks once again Thom.

Regards,

Nick