• Obtain demo undertaking – 41.1 Kb

Image 1

Introduction

This text is a straightforward how-to article on utilizing the Adobe Acrobat 7 ActiveX management inside a C++ utility utilizing MFC. The pattern undertaking included makes use of a minimal MDI MFC utility to point out that you should utilize a number of situations of the management inside the similar utility. The code was stored easy and slim in order that it centered extra on the precise content material. The supply code and undertaking file was written utilizing Microsoft Visible C++ .NET 2003, however the code can simply be built-in into any model of Visible C++.

Background

Earlier variations of Adobe Acrobat didn’t enable the ActiveX management for use inside an exterior utility. Based on the Acrobat Developer FAQ, the ActiveX management was solely developed to be used within the Microsoft Web Explorer Internet Browser and was not supported or licensed to be used in another utility. With the discharge of Adobe Acrobat 7, the Acrobat Reader ActiveX management is now totally supported and documented, this offers utility writers rather more flexibility when distributing PDF recordsdata to prospects. The PDFs which are opened with this management can even make the most of the Acrobat JavaScript to speak with one another simply as they might in the event that they have been opened inside an internet web page.

Utilizing the code

The code could be very easy and simple to make use of, it’s primarily supposed to point out you the way to import the management into your individual utility and never only for copying and pasting the code from the demo supply. I selected to make use of a CWnd because the view as an alternative of a CFormView for the demo undertaking, this may provide help to perceive the way to create the management programmatically as an alternative of simply plopping it on a dialog from a toolbox.

See also  What’s it Going to Take to Run Photoshop CS4? A Real World Guide to the Hardware You’ll Need

Step one to utilizing the Acrobat Reader 7 management is to create an MFC class from an ActiveX management utilizing the Class Wizard. Whereas within the Class View tab, proper click on in your undertaking and choose “Add->Add Class…” and select the choice “MFC Class From ActiveX”.

Image 2

Now click on “Open” and a brand new dialog will seem. Underneath the part labeled “Available ActiveX Controls”, discover and choose the “Adobe Acrobat 7.0 Browser Document <1.0>” management from the combo field. The interface “IAcroAXDocShim” will seem within the checklist of interfaces. Choose the interface and click on the “>” arrow so as to add a category for it. The wizard will then create the category CAcroAXDocShim and add it to your undertaking.

Image 3

You’re nearly completed, now you simply want to make use of this generated class in your individual window. Add a member variable in your window view class that’s of kind “CAcroAXDocShim“:

#embrace "CAcroAXDocShim.h"

class CAcroViewer : public CWnd
{
public:
    ...

// Attributes
personal:
    CAcroAXDocShim m_ctrl;
};

Now that you’ve got added the variable, you simply must create it and use it to open PDF Recordsdata. To create it, first create a management ID, which is simply an integer that isn’t presently being utilized by one other management in your utility. Now, on the finish of your window’s OnCreate handler, you name the management’s Create perform. The primary parameter wanted is a string for the window title, you should utilize something for this worth, I selected “AdobeWnd“. The following parameter is the window type, you want WS_CHILD to make it a baby and WS_VISIBLE to make it seen. Subsequent is a RECT for the window place, I used all 0’s as a result of I made a WM_SIZE handler to resize the management when the window is resized. The following parameters are the window guardian (this), and the management ID that was created.

const int CTRL_ID = 280;

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

    //Create the management, simply be certain to make use of WS_CHILD and WS_VISIBLE.
    if (!m_ctrl.Create("AdobeWnd", WS_CHILD | WS_VISIBLE, 
                                      CRect(, , , ), this, CTRL_ID))
    {
        AfxMessageBox("Failed to create adobe wnd");
        return -1;
    }

    return ;
}

The ActiveX management is now created and visual in your utility. The one drawback now’s that its measurement is 0. To repair this we add a WM_SIZE handler to the window and resize the management to match the window’s consumer rect. We should ensure that the window is legitimate first by calling IsWindow(m_hWnd). After this name we simply merely name GetClientRect() and go that rect to MoveWindow() for our management.

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

    //Resize the management with the window.
    if (IsWindow(m_hWnd))
    {
        CRect rc;
        GetClientRect(rc);
        m_ctrl.MoveWindow(rc);
    }
}

The one factor left now’s to open a PDF file. This may be carried out with one easy name to LoadFile on the management. The file parameter may be both a file on the native file system or a URL to a file on an HTTP server.

void CAcroViewer::Open(const char *file)
{
    //Simply load the file that's opened.
    m_ctrl.LoadFile(file);
}

Factors of curiosity

Sadly, though this management is now outdoors of the Microsoft Web Explorer Browser, it nonetheless appears to endure from the bugs that it has had in all different variations of the Acrobat Reader. Often it appears essential to open up Process Supervisor and “End Task” the ” utility to get issues work correctly once more. It is not an issue associated to this utility, it is an issue with the management itself. When opening and shutting a number of PDF recordsdata from inside Web Explorer, you sometimes run into an issue the place the PDF viewer simply freezes. I hoped that Adobe would have mounted this bug with the discharge of Acrobat Reader 7, however it seems to be nonetheless there.

See also  Adobe Dreamweaver Portable 2021 Download

Conclusion

I hope that this text has helped these of you who need to use PDF recordsdata inside your individual functions and solely have the Acrobat Reader. When you have the total model of Adobe Acrobat, there are various different choices open to you for utilizing PDF recordsdata inside your individual functions, corresponding to OLE automation. I’ve labored fairly extensively with OLE automation of Acrobat inside C++ and C# functions and it’s a a lot better method usually however is proscribed to Acrobat Skilled and never supported on programs that solely have the Acrobat Reader put in.

Leave a Reply

Your email address will not be published.