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

Toolbutton Close Doc

mike_zet
Registered: Feb 4 2008
Posts: 7

Hi everybody.
I need to create a Toolbutton within a PDF Doc which will by able to close this document. I’ve tried with Close Doc command in Exec: line but then the whole Acrobat crashes. If You have any suggestions or tips please do let me know.

My Product Information:
Acrobat Pro 7.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please explain what you mean by a toolbutton and the "Exec" line.

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

mike_zet
Registered: Feb 4 2008
Posts: 7
Hi,
Sorry if I wasn't accurate. What I meant is this: I was able to create a Tool Button using this code:
app.addToolButton({
cName: "Return",
cExec: "……………",
cTooltext: "Return",
nPos: -1
});
but not every command can be put in line “cExec:”. What I would like to achieve is that this Tool Button, which will be created within, let say second document, will close that 2nd doc and take mi to the previous one. It will be also nice if I could open this 2nd doc and create Tool Button from the link in the first doc.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The only restriction on using the "doc.closeDoc()" function is that if it's used in Reader, the document being closed must have Save Rights. Other than that it's not a problem.

You're crash is due to the context inwhich this function is being called. It's been known for a long time that closing a document from certain execution contexts crashes Acrobat. The problem may be that the document closes, and becomes invalid, before the JavaScript engine finishes using the document object.

The solution is to move the context of the close somewhere else. For example, make a bookmark that calls the close menu item, then execute this bookmark from your button. Or place the code for closing in a timeout.

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

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

mike_zet
Registered: Feb 4 2008
Posts: 7
Thanks very much for your tips. I’ve made use of them. The last thing I need is a Java code which will do exactly the same as an action:
Go to page in another Document
File name: c:\.............. . pdf
Destination name: DEST1
I need the same functionality but within action: Run a JavaScript.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Look in the Acrobat JavaScript Reference at the app.openDoc() fucntion. It has a input for navigating to a named desination in the opened document.

Also, if you have control over the PDF that's being opened, you can get a Doc Object from the openDoc function by setting the following line in a document script in the target PDF

this.disclosed = true;

This line tells Acrobat to expose the Doc Object to JavaScript. Allowing you to set the page number, like this:

var oDoc = this.openDoc(myDocPath);
oDoc.pageNum = 3; // to navigate to page 4


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/]http://www.adobe.com/devnet/acrobat/[/url]

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