Click here to Skip to main content
13,502,077 members
Click here to Skip to main content
Add your own
alternative version


74 bookmarked
Posted 9 Feb 2005

Adobe ActiveX Control with MFC

, 9 Feb 2005
Rate this:
Please Sign up or sign in to vote.
How to use the Adobe Acrobat 7 Reader ActiveX control inside a C++ application.


This article is a simple how-to article on using the Adobe Acrobat 7 ActiveX control within a C++ application using MFC. The sample project included uses a minimal MDI MFC application to show that you can use multiple instances of the control within the same application. The code was kept simple and slim so that it focused more on the actual content. The source code and project file was written using Microsoft Visual C++ .NET 2003, but the code can easily be integrated into any version of Visual C++.


Previous versions of Adobe Acrobat did not allow the ActiveX control to be used within an external application. According to the Acrobat Developer FAQ, the ActiveX control was only developed for use in the Microsoft Internet Explorer Web Browser and was not supported or licensed for use in any other application. With the release of Adobe Acrobat 7, the Acrobat Reader ActiveX control is now fully supported and documented, this gives application writers much more flexibility when distributing PDF files to customers. The PDFs that are opened with this control can also take advantage of the Acrobat JavaScript to communicate with each other just as they would if they were opened within a web page.

Using the code

The code is very simple and straightforward to use, it is mainly intended to show you how to import the control into your own application and not just for copying and pasting the code from the demo source. I chose to use a CWnd as the view instead of a CFormView for the demo project, this will help you understand how to create the control programmatically instead of just plopping it on a dialog from a toolbox.

The first step to using the Acrobat Reader 7 control is to create an MFC class from an ActiveX control using the Class Wizard. While in the Class View tab, right click on your project and select "Add->Add Class..." and choose the option "MFC Class From ActiveX".

Now click "Open" and a new dialog will appear. Under the section labeled "Available ActiveX Controls", find and select the "Adobe Acrobat 7.0 Browser Document <1.0>" control from the combo box. The interface "IAcroAXDocShim" will appear in the list of interfaces. Select the interface and click the ">" arrow to add a class for it. The wizard will then create the class CAcroAXDocShim and add it to your project.

You are almost finished, now you just need to use this generated class in your own window. Add a member variable in your window view class that is of type "CAcroAXDocShim":

#include "CAcroAXDocShim.h"

class CAcroViewer : public CWnd

// Attributes
    CAcroAXDocShim m_ctrl;

Now that you have added the variable, you just need to create it and use it to open PDF Files. To create it, first create a control ID, which is just an integer that is not currently being used by another control in your application. Now, at the end of your window's OnCreate handler, you call the control's Create function. The first parameter needed is a string for the window name, you can use anything for this value, I chose "AdobeWnd". The next parameter is the window style, you need WS_CHILD to make it a child and WS_VISIBLE to make it visible. Next is a RECT for the window position, I used all 0's because I made a WM_SIZE handler to resize the control when the window is resized. The next parameters are the window parent (this), and the control ID that was created.

const int CTRL_ID = 280;

int CAcroViewer::OnCreate(LPCREATESTRUCT lpCreateStruct)
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    //Create the control, just make sure to use WS_CHILD and WS_VISIBLE.
    if (!m_ctrl.Create("AdobeWnd", WS_CHILD | WS_VISIBLE, 
                                      CRect(0, 0, 0, 0), this, CTRL_ID))
        AfxMessageBox("Failed to create adobe wnd");
        return -1;

    return 0;

The ActiveX control is now created and visible in your application. The only problem now is that its size is 0. To fix this we add a WM_SIZE handler to the window and resize the control to match the window's client rect. We must make sure that the window is valid first by calling IsWindow(m_hWnd). After this call we just simply call GetClientRect() and pass that rect to MoveWindow() for our control.

void CAcroViewer::OnSize(UINT nType, int cx, int cy)
    CWnd::OnSize(nType, cx, cy);

    //Resize the control with the window.
    if (IsWindow(m_hWnd))
        CRect rc;

The only thing left now is to open a PDF file. This can be done with one simple call to LoadFile on the control. The file parameter can be either a file on the local file system or a URL to a file on an HTTP server.

void CAcroViewer::Open(const char *file)
    //Just load the file that is opened.

Points of interest

Unfortunately, even though this control is now outside of the Microsoft Internet Explorer Browser, it still seems to suffer from the bugs that it has had in all other versions of the Acrobat Reader. Occasionally it seems necessary to open up Task Manager and "End Task" the "AcroRd32.exe" application to get things work properly again. It's not a problem related to this application, it's a problem with the control itself. When opening and closing several PDF files from within Internet Explorer, you occasionally run into a problem where the PDF viewer just freezes. I was hoping that Adobe would have fixed this bug with the release of Acrobat Reader 7, but it appears to be still there.


I hope that this article has helped those of you who want to use PDF files within your own applications and only have the Acrobat Reader. If you have the full version of Adobe Acrobat, there are many other options open to you for using PDF files within your own applications, such as OLE automation. I have worked pretty extensively with OLE automation of Acrobat within C++ and C# applications and it is a much better approach in most cases but is limited to Acrobat Professional and not supported on systems that only have the Acrobat Reader installed.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I live in the Nothern Virginia/Washington D.C. area. I have been working in the software industry since 1995. My skills are primarily in C++ and Java on Windows and Unix platforms but I also work with C# and some other programming languages (even PL/I and COBOL when necessary!).

Check out my software web site:

You may also be interested in...


Comments and Discussions

QuestionA bug report Pin
Member 857373425-Feb-15 23:52
memberMember 857373425-Feb-15 23:52 
SuggestionHow to use this example in a dialog window Pin
Sepp Obermayer15-Apr-13 21:09
memberSepp Obermayer15-Apr-13 21:09 
GeneralCrash on Tab-out Pin
chaau10-Jun-10 14:08
memberchaau10-Jun-10 14:08 
GeneralActiveX Control wrapper class(es) for Acrobat reader Pin
Anita Banerjee28-Aug-09 12:38
memberAnita Banerjee28-Aug-09 12:38 
QuestionQuery Pin
Member 319901212-Aug-09 19:14
memberMember 319901212-Aug-09 19:14 
Questionhow to update pdf source file... Pin
raj2313621-Jun-09 21:31
memberraj2313621-Jun-09 21:31 
QuestionHow to create pdf file ? Pin
jasuja_moris31-Oct-08 18:38
memberjasuja_moris31-Oct-08 18:38 
GeneralAdobe Acrobat 8 Reader Pin
DJM8-Apr-08 3:17
memberDJM8-Apr-08 3:17 
GeneralBookmarks Pin
Eng.Habeba5-Mar-08 22:18
memberEng.Habeba5-Mar-08 22:18 
GeneralPDF files not displayed while opened with a deny write share Pin
triendl.kj6-Jan-08 23:02
membertriendl.kj6-Jan-08 23:02 
GeneralRe: PDF files not displayed while opened with a deny write share Pin
triendl.kj7-Jan-08 1:15
membertriendl.kj7-Jan-08 1:15 
Generalscrolling the pdf file Pin
parisaeslambolchi21-Aug-07 8:06
memberparisaeslambolchi21-Aug-07 8:06 
QuestionDisable right click menu from PDF Pin
Raj248120-Aug-07 23:55
memberRaj248120-Aug-07 23:55 
AnswerRe: Disable right click menu from PDF Pin
Bryan_Han7-Oct-10 20:40
memberBryan_Han7-Oct-10 20:40 
AnswerRe: Disable right click menu from PDF Pin
Bryan_Han7-Oct-10 21:37
memberBryan_Han7-Oct-10 21:37 
GeneralVC++ 6.0 Pin
Fahad Ahmed6-Jun-07 9:34
memberFahad Ahmed6-Jun-07 9:34 
QuestionDoes it really work? Pin
mark-w15-Apr-07 17:46
membermark-w15-Apr-07 17:46 
AnswerRe: Does it really work? Pin
eusto6-Jul-07 2:21
membereusto6-Jul-07 2:21 
QuestionHow to refresh the dialog? Pin
rootdial22-Mar-07 8:12
memberrootdial22-Mar-07 8:12 
GeneralQuery for finished Pin
MGDBP8-Mar-07 23:10
memberMGDBP8-Mar-07 23:10 
GeneralOpening password protected pdfs Pin
flumb22-Feb-07 0:32
memberflumb22-Feb-07 0:32 
GeneralPrint & Right Click Pin
eusto5-Feb-07 11:36
membereusto5-Feb-07 11:36 
GeneralIAcroAXDocShim.LoadFile COMException Pin
jim_little_20001-Feb-07 13:44
memberjim_little_20001-Feb-07 13:44 
Questioncan i do the same with ATL only without needing MFC? Pin
cordoval20-Jan-07 11:29
membercordoval20-Jan-07 11:29 
GeneralLinks to other PDFs and named destination Pin
pavelmaj4-Aug-06 6:18
memberpavelmaj4-Aug-06 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 9 Feb 2005
Article Copyright 2005 by rocky_pulley
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid