Extracting InDesign CS4 Graphics using C# and COM


I'm trying to get details of the graphics in an InDesign file. For technical reasons I'm using COM. Not my favourite, as (discussed elsewhere in StackOverflow) you have to spend half your life casting. In Theory (!), the code snippet belwo should work. Intellisense shows doc.AllGraphics as returning objects.

The CS3 scripting reference at http://www.indesignscriptingreference.com/CS3/JavaScript/Document.htm shows it as Array of Graphic

for (int g = 1; g <= doc.AllGraphics.Count; g++) {
  InDesign.Graphic graphic = (InDesign.Graphic) doc.AllGraphics[ g ];

However, I get this error message:

Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Graphic'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6AE52037-9E4E-442D-ADFC-2D492B4BCBEF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I've tried using alternative constructs to return an object and then cast this to an Indesign.Graphic. All fail with the same error. I can't believe that Adobe missed including this interface.

Any suggestions as to a solution so I can get the graphic content?

asked on Stack Overflow Jan 25, 2010 by wilson32

2 Answers


I am running Win7 64 and CS4 here and had the E_NOInterface message too. It took me 6 hours to solve it via google, try and error. On my way thru the internet I saw your posting here and came back to write you what helped me.

During install the Com-Objects are not registered correctly. To solve this

  • go to the folder

    • for cs3: %ALLUSERSPROFILE%\Adobe\InDesign\Version 5.0\Scripting Support\5.0 in my case: C:\ProgramData\Adobe\InDesignVersion 5.0\Scripting Support\5.0

    • for cs4: %ALLUSERSPROFILE%\Adobe\InDesign\Version 5.0\Scripting Support\6.0

  • rename the file "Resources for Visual Basic.tlb" to "Resources for Visual Basic.tlb.old"

  • open up a command window as administrator

  • go to the indesign-Folder, in my case C:\Program Files (x86)\Adobe\Adobe InDesign CS4

  • and launch indesign in the command window by typing:

    indesign.exe -type

wait for the launch and then you are good to go. with this parameter it registeres the components.

I found that solution here

answered on Stack Overflow Feb 10, 2010 by cafenervosa • edited Dec 12, 2011 by sjngm

This has just happened to me, and I landed here from Google! I managed to solve it so will add the solution here for the next time I run into it!

Simply, delete the Resources for Visual Basic.tlb file that may be at the path of C:\ProgramData\Adobe\InDesign\Version 8.0\en_GB\Scripting Support\8.0 and open InDesign as Administrator and wait for it to run.

I found the C# application to hang when I ran it next, so had to close InDesign down, and let C# open it up by itself! Example:

        Type type = Type.GetTypeFromProgID("InDesign.Application");
        Application app = (Application)Activator.CreateInstance(type);

        var doc = app.Documents.Add();

        for (var i = 0; i < 5; i++)
answered on Stack Overflow May 14, 2016 by user3791372

User contributions licensed under CC BY-SA 3.0