Search code examples
pdfmacrosacrobat

Autoclose Macro in a PDF


For testing purposes I am trying to create a PDF that, upon opening, automatically closes itself and closes Acrobat Reader. Similar to having an Auto_Open macro in Word that executes: Application.Quit.

I have Acrobat Professional 9.0 but I cannot see how to do that. However, I see discussions of "Actions" (Acrobat Macros) on the Acrobat website.

Thanks.


Solution

  • Actions are not quite what you are looking for…

    And Acrobat/Reader can not completely do what you are asking it for… For security reasons, it is not possible to programmatically terminate Acrobat/Reader. So, Quitting is not possible; all you can do is closing the document.

    You would use Acrobat JavaScript for that. In order to see that it really works, I suggest to first try out a two-page document. To the second page, you add the following PageOpen script (later on, you can do that with the first page too):

    this.dirty = false ;
    this.closeDoc() ;
    

    You create a PageOpen script by displaying the page tumbnails, and then select the context menu of the page you want to access. There you open the Page Properties… dialog, and switch to the Page Actions tab. Select Run a JavaScript as action for PageOpen, and add the code above.

    Update, after comment by Neil Weicher :

    If you want to delay the closing, you could use the setTimeOut() method, as showing in this example (which also uses the argument for closing the document without asking whether to save (the equivalent of setting the dirty flag to false); the delay is 5 seconds (5000 milliseconds)):

    myDelay = app.setTimeOut("this.closeDoc(true) ; app.clearTimeOut(myDelay) ;" , 5000) ;
    

    Note: although the timeout object should get reset when the document closes, it is safer to do it in the delayed script.

    And that should do it.