I was looking for a simple way of closing Adobe Reader document (PDF) and leaving intact other open documents and the Reader itself.
Presented on this page, the AdobeAcrobat7 class enumerates opened pdf documents. It also can close any Acrobat document window or all document windows and more.
Use the following code to test the class:
LOCAL oReader As AdobeAcrobat7, oDoc As AdobeDocument
oReader = CREATEOBJECT("AdobeAcrobat7")
IF NOT oReader.AcrobatIsRunning()
cDocument = GETFILE("PDF", "Acrobat document",;
"Open",0,"Open Acrobat Reader document")
IF NOT oReader.OpenAcrobatDocument(cDocument)
= MESSAGEBOX("Could not open " +;
"Acrobat Reader document. ",;
FOR EACH oDoc IN oReader.documents
IF oDoc.filename = "mydoc.pdf"
IF MESSAGEBOX("Exit Acrobat?",32+4)=6
When started, the AcrobatReader creates a window with the class name AdobeAcrobat. All pdf documents opened are its child windows with the class name AcrobatMDIChildWnd. Use Microsoft Spy++ or a similar tool to find out more.
Once the window class name is known, it is easy to find the process linked to this window and terminate it. This will also terminate all open pdf documents. So it does not help when only one document window is to be closed.
* * *
It is possible to enumerate all AcrobatMDIChildWndwindows currently existing. Yet no such window can be closed by calling the DestroyWindow: a thread cannot use DestroyWindow to destroy a window created by a different thread.
Acrobat document window closes upon receiving a special window message:
* * *
If AdobeAcrobat settings are configured to display each PDF document in a separate window, then all document windows are created with window class AcrobatSDIWindow. Which means the code sample will not work, since it searches windows with AdobeAcrobat class name.
Still this approach will work after reshaping the code, because each SDI window has a menu that can be reached through SendMessage calls.
Menu IDs in the Adobe Reader 8.1 seem to be different from those used in previous versions, which prevents the code sample from working properly with the newer Adobe Reader version.
* * *
In Acrobat Reader 9 the class of the main window is "AcrobatSDIWindow", not "AdobeAcrobat" anymore. The number of open windows of this class corresponds to the the number of PDF documents currently open. Each AcrobatSDIWindow has a separate menu. All main Acrobat windows are aware of other open Acrobat documents.
* * *
Jan.26, 2009: Starting with version 9 of the Adobe Reader for Windows, may be even with an earlier 8+ version, the preference "Show each document in its own window (requires restart)" is no longer available. There is a TechNote from Adobe (kb405108) explaining why such questionable decision was ever taken -- no more MDI.
Credits: PHP (4.4.9), an HTML-embedded scripting language,
MySQL (5.1.55-log), the Open Source standard SQL database,
Version 4, freeware HTML Editor of choice. Hosted by Korax Online Inc.