Extracting InDesign CS4 Graphics using C# and COM(使用 C# 和 COM 提取 InDesign CS4 图形)
问题描述
我正在尝试获取 InDesign 文件中图形的详细信息.出于技术原因,我使用的是 COM.不是我最喜欢的,因为(在 StackOverflow 的其他地方讨论过)你必须花费一半的时间来铸造.在 Theory (!) 中,下面的代码片段应该可以工作.Intellisense 将 doc.AllGraphics 显示为返回 objects.
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 显示为 Array of Graphic
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?
推荐答案
这件事刚刚发生在我身上,我从谷歌登陆这里!我设法解决了它,所以下次遇到它时会在这里添加解决方案!
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!
只需删除 Resources for Visual Basic.tlb
文件,该文件可能位于 C:ProgramDataAdobeInDesignVersion 8.0en_GBScripting Support8.0
并以管理员身份打开 InDesign 并等待它运行.
Simply, delete the Resources for Visual Basic.tlb
file that may be at the path of C:ProgramDataAdobeInDesignVersion 8.0en_GBScripting Support8.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 图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C# 和 COM 提取 InDesign CS4 图形
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30