使用C#和COM提取InDesign CS4图形 [英] Extracting InDesign CS4 Graphics using C# and COM

查看:100
本文介绍了使用C#和COM提取InDesign CS4图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在InDesign文件中获取图形的详细信息.由于技术原因,我正在使用COM.不是我的最爱,因为(必须在StackOverflow的其他地方讨论过)您必须花费一半的时间进行铸造.在理论(!)中,代码片段belwo应该起作用.Intellisense将 doc.AllGraphics 显示为返回 对象 .

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.

位于 http://www.indesignscriptingreference.com/CS3/上的CS3脚本参考JavaScript/Document.htm 将其显示为 图形数组

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:

无法转换类型为COM的对象'System .__ ComObject'到接口类型'InDesign.Graphic'.这项作业失败,因为QueryInterface调用在接口的COM组件上与IID'{6AE52037-9E4E-442D-ADFC-2D492B4BCBEF}'由于以下错误而失败:否支持这样的接口(异常从HRESULT:0x80004002(E_NOINTERFACE).

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)).

我尝试使用替代构造返回对象,然后将其强制转换为 Indesign.Graphic .所有失败均出现相同的错误.我不敢相信Adobe会错过这个界面.

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?

推荐答案

这刚刚发生在我身上,我从Google登陆了!我设法解决了这个问题,因此下次我碰到它时,将在这里添加解决方案!

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!

只需删除 Visual Basic.tlb资源文件,该文件可能位于 C:\ ProgramData \ Adob​​e \ InDesign \ Version 8.0 \ en_GB \ Scripting Support \ 8.0 并以管理员身份打开InDesign并等待其运行.

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.

下一次运行它时,我发现C#应用程序挂起,因此必须关闭InDesign,然后让C#自己打开它!示例:

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++)
            doc.Pages.Add(idLocationOptions.idAtBeginning);

这篇关于使用C#和COM提取InDesign CS4图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆