none
Trying to add PDF to Word via AddOLEObject fails

    Question

  • I'm trying to generate an automated report from the web using word. I want the ability to add pdf's with the exact functionality as the Insert->Object->Adobe Acrobat Document into my word document. Going through those steps to add a pdf document works as intended.

    However when I try to do it through code, Word is producing an error. Here's the code I've been using:

          object missing = System.Reflection.Missing.Value;
          Application oWordApp = new Application();
          Document oWordDoc = oWordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
          oWordApp.Visible = true;
          
          object filename = "[myfilename]";
          object classType = "AcroExch.Document.7";
          object oFalse = false;
          //oWordApp.Selection.InlineShapes.AddOLEObject(ref classType, ref filename, ref oFalse, ref oFalse, ref missing, ref missing, ref missing, ref missing);
          oWordApp.Selection.InlineShapes.AddOLEObject(ref missing, ref filename, ref oFalse, ref oFalse, ref missing, ref missing, ref missing, ref missing);

     When I use the following above code with a docx, or txt, or even jpg, it works perfectly. However whenever I try to use it with a PDF, I get the following error message in Word: "The server application, source file, or item cannot be found. Make sure the application is properly installed, and that it has not been deleted, moved, renamed, or blocked by policy."

    When I uncomment out the other call to AddOLEObject (using the classType object), I get the following error message from Word:

    "The program used to create this object is AcroExch. That program is either not installed on your computer or it is not responding. To edit this object, install AcroExch or ensure that any dialog boxes in AcroExch are closed."

    That message doesn't change when switching the classType between AcroExch, AcroExch.Document or AcroExch.Document.7

    Here's the system details:
    Win 7 Pro x64
    Office 2010 Pro Plus x64
    Adobe Reader 9
    CutePDF Writer

     A resolution to this would be fantastic. Thanks for any input in advance.

    Monday, June 21, 2010 10:10 PM

Answers

  • When I press Alt+F9, it shows the following:

    { EMBED AcroExch.Document.7 }

    However I did find out what the issue is - x64.

    I installed office x86 onto XPMode, and it worked like a charm.

    • Marked as answer by David.A360 Tuesday, June 22, 2010 10:07 PM
    Tuesday, June 22, 2010 5:16 PM

All replies

  • Hi David

    AcroExch is (obviously) not Microsoft software - it might be a good idea to ask this question in a venue that supports the application. Or ask the manufacturer. Those folks would be best informed about the OLE interfaces AcroExch provides.

    Are you certain that Word is inserting the PDF files using OLE automation to AcroExch? This sounds to me as if AcroExch is not functioning as an OLE Server application in the manner required to embed a PDF file this way. Whether it can is a question the manufacturer would need to answer.

    An alternate approach would be to build these files as Open XML files (without automatiing the Word application at all). This would also avoid having to access any other application as an OLE Server (although that software would still be required when the user opens the document at a later time). You can find out more about the Office 2007 Open XML file format at OpenXMLDeveloper.org. There's also an Open XML SDK and a forum for that on this server. This is the recommended way of generating Word documents in a server environment.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 22, 2010 6:05 AM
    Moderator
  • As an update:

    I tried generating a Macro to do the same thing in Word, and it looks like the following:

    Sub pdf()
    '
    ' pdf Macro
    '
    '
      Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.7", _
        FileName:="", LinkToFile:=False, DisplayAsIcon:=False
    End Sub

    The first thing I noticed was that there was no filename. If I run the macro as is, it prompts me for the file, I select it, and it inserts it without issue.

    When I then put the filename in, I get the same error that I was getting above - "The program used to create this object is AcroExch. That program is either not installed on your computer or it is not responding. To edit this object, install AcroExch or ensure that any dialog boxes in AcroExch are closed."

    Now when I  switch the path to a docx in the same folder, it inserts without issue, even with the classtype remaining as AcroExch.Document.7. It's like there's something wrong with the filename when I insert it.

    Obviously I've checked and rechecked that the file path is correct.

     

    Tuesday, June 22, 2010 4:52 PM
  • Another update - changing the LinkToFile:=true corrects this issue. However I need it to work with that value = false
    Tuesday, June 22, 2010 4:55 PM
  • Hi David

    I really recommend you contact the software manufacturer. It's certainly an issue with that object model interface and has nothing to do with the Word interface.

    FWIW Word will insert this as a field code, probably a LINK field. Pressing Alt+F9 should show you that field. What's between the { field brackets }?

    Also, the InlineShape object has a LinkFormat property, which in turn has a BreakLink method. You could try using that after the shape has been inserted to break the link to the file. Whether the object can afterwards be opened in the PDF software you'd have to test...


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 22, 2010 5:12 PM
    Moderator
  • When I press Alt+F9, it shows the following:

    { EMBED AcroExch.Document.7 }

    However I did find out what the issue is - x64.

    I installed office x86 onto XPMode, and it worked like a charm.

    • Marked as answer by David.A360 Tuesday, June 22, 2010 10:07 PM
    Tuesday, June 22, 2010 5:16 PM
  • Hi Dave

    Glad you tracked it down.

    FWIW it appears, even if you have the "Linktofile" parameter set to true in the code that the result is NOT linked. So that wouldn't be something to worry about if you needed to have that code run on 64-bit.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 22, 2010 5:20 PM
    Moderator
  • Sorry, I misread what you were asking for. The linktofile=false produces an embed and linktofile=true produces a link as it should. I think the solution to this is to utilize office x86. Maybe someday (when I'm dead) Adobe will start producing x64 products. At leas flash 64-bit flash is on its way.

    Tuesday, June 22, 2010 5:33 PM
  • Sorry, I misread what you were asking for. The linktofile=false produces an embed and linktofile=true produces a link as it should. I think the solution to this is to utilize office x86. Maybe someday (when I'm dead) Adobe will start producing x64 products. At leas flash 64-bit flash is on its way.


    OK, that makes sense. But then what I'm suggest is you test for 64-bit is to use LinkToFile = True, then LinkFormat.BreakLink to turn the LINk field into an Embed field.
    Cindy Meister, VSTO/Word MVP
    Tuesday, June 22, 2010 7:14 PM
    Moderator
  • Hmmm. I've already unisntalled office x64 and swapped it out for office x86. I will try this though if I ever get the chance.
    Tuesday, June 22, 2010 10:08 PM
  • Had the same problem. This will fix your issue.

     

    Disabling Protected Mode in Adobe Reader X

    1. Open Adobe Reader X.

    2.From Edit menu select Preferences, Preferences dialog box appears.

    3.Select General category on the list, uncheck or remove tick mark for “Enable protected mode at startup”

    Adobe Reader’s Protected Mode will be turned off.

    • Proposed as answer by Bob Wasserman Wednesday, February 23, 2011 2:00 AM
    Wednesday, February 16, 2011 12:34 PM
  • Had the same problem. This will fix your issue.

     

    Disabling Protected Mode in Adobe Reader X

    1. Open Adobe Reader X.

    2.From Edit menu select Preferences, Preferences dialog box appears.

    3.Select General category on the list, uncheck or remove tick mark for “Enable protected mode at startup”

    Adobe Reader’s Protected Mode will be turned off.

    You may have this issue in the circumstance Adobe Reader was just updated and you haven't launched Reader since the update.  I fixed the issue simply by launching Adobe Reader on its own and letting it configure the install.  Once that step happened, everything works.  Didn't have to mess with disabling any Reader settings in Reader 9.
    Friday, February 18, 2011 9:13 PM
  • thanks Bob, it worked out!
    Thursday, March 10, 2011 4:25 PM
  • This worked for us too.  Glad I found your reply.
    Wednesday, April 20, 2011 8:35 PM
  • All of the previous solutions were too confusing from an end user perspective. Bob, you nailed it. Simple steps. Works like a charm. - Ravi
    Friday, June 10, 2011 6:10 PM
  • The solution from Arkandor IT Solutions above does not appear to work with Office 2010 64bit. John

    Wednesday, August 17, 2011 10:53 AM
  • Hi David

    I've just stumbled across your macro and was very exciting when it worked!

    Sub pdf()
    '
    ' pdf Macro
    '
    '
      Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.7", _
        FileName:="", LinkToFile:=False, DisplayAsIcon:=False
    End Sub

    I was wondering if there was a way to change this so that when it inserts the pdf file into word it displays it as an icon?  - Sorry, I know nothing about coding...

    Thursday, December 08, 2011 11:49 AM
  • There is a workaround for this.  We are all used to selecting the tab 'Create from File' when we want to use an existing file.  If you will force yourself to double-click the 'Adobe Acrobobat Document' from the list on the 'Create New' tab screen instead, you will be able to browse to your PDF file, select it, and it will insert without error.  Be sure to check the 'Display as icon' box BEFORE you pick your file.

    It's a strange work flow but it works. Hope this helps!

    Tuesday, July 31, 2012 9:16 PM
  • This is fantastic!

    I was really worried that I would have to install some older 32 bit version of office or use XPMode in order to do something as simple as embed a PDF document into my Word file.

    Many, many thanks!

    Tuesday, September 25, 2012 6:02 PM
  • Dear MsPEBKAC:
    Avatar of MsPEBKAC

    MsPEBKAC

    Intergraph Process, Powe...

    5 Points100
    Recent Achievements
    First Forums Reply

    Wow, I don't know how you figured this out, but using Insert, Object Create New, checking 'Display as icon, double clicking on Adobe Acrobat Document, then selecting the PDF file WORKS right away.

    The other advice where you uncheck Enable Protected Mode on Startup in Adobe Reader X did not work for me.

    Our users have Office 2010 64 bit, I have both 32 and 64 bit and can confirm that is a 64bit office problem.

    Thanks so much. I am keeping this work around information in our knowledge base.


    • Edited by Tech_Etown Thursday, October 25, 2012 2:21 PM
    Thursday, October 25, 2012 2:18 PM
  • I stumbled around trying to find this setting for way too long. I guess in some versions it is located under the 'Security (Enhanced)' category rather than the General category...

    1. Open Adobe Reader X.

    2.From Edit menu select Preferences, Preferences dialog box appears.

    3.Select General [Security (Enhanced)] category on the list, uncheck or remove tick mark for “Enable protected mode at startup”

    Adobe Reader’s Protected Mode will be turned off.

    Wednesday, October 31, 2012 2:43 PM
  • What about for Adobe XI Pro? This version does not have an option for "Enable protected mode at startup" under [Security (Enhanced)]. How can I turn it off? Thanks!

    Oh! I'm using Windows 2010 64 bit and Adobe XI Pro. Thanks!

    Tuesday, July 02, 2013 2:53 PM