使用 C# 和 COM 提取 InDesign CS4 图形
我正在尝试获取 InDesign 文件中图形的详细信息。出于技术原因,我使用 COM。不是我最喜欢的,因为(在 StackOverflow 的其他地方讨论过)你必须花半生的时间来选角。理论上(!),下面的代码片段应该可以工作。 Intellisense 将 doc.AllGraphics 显示为返回对象。
CS3 脚本参考位于 http://www.indesignscriptingreference.com/CS3/JavaScript/Document .htm 将其显示为图形数组
for (int g = 1; g <= doc.AllGraphics.Count; g++) {
InDesign.Graphic graphic = (InDesign.Graphic) doc.AllGraphics[ g ];
....
}
但是,我收到此错误消息:
无法转换 COM 对象类型 “System.__ComObject”到接口类型 “InDesign.Graphic”。这个操作 由于 QueryInterface 调用失败 在接口的 COM 组件上 带独立ID '{6AE52037-9E4E-442D-ADFC-2D492B4BCBEF}' 由于以下错误而失败:否 支持此类接口(异常 来自 HRESULT:0x80004002 (E_NOINTERFACE))。
我尝试使用替代构造返回一个对象,然后将其转换为 Indesign.Graphic。全部失败并出现相同的错误。我不敢相信 Adobe 竟然错过了这个界面。
有关解决方案的任何建议,以便我可以获得图形内容吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这里运行 Win7 64 和 CS4,也有 E_NOInterface 消息。
我花了6个小时通过google、尝试和错误才解决这个问题。在我通过互联网的路上,我看到了你在这里发的帖子,然后回来给你写了一些对我有帮助的东西。
在安装过程中,Com-Object 未正确注册。要解决此问题
转到文件夹
对于 cs3:
%ALLUSERSPROFILE%\Adobe\InDesign\Version 5.0\Scripting Support\5.0
就我而言:
C:\ProgramData\Adobe\InDesignVersion 5.0\Scripting Support\5.0
对于 cs4:
%ALLUSERSPROFILE%\Adobe\InDesign\Version 5.0\Scripting Support\6.0
将文件“Resources for Visual Basic.tlb”重命名为“Resources for Visual Basic.tlb” Visual Basic.tlb.old”
以管理员身份打开命令窗口
转到 indesign-Folder,在我的例子中
C:\Program Files (x86)\Adobe\Adobe InDesign CS4
并在命令窗口中键入以下内容启动 indesign:
等待启动,然后就可以开始了。它使用此参数注册组件。
我在这里找到了解决方案
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:
wait for the launch and then you are good to go. with this parameter it registeres the components.
I found that solution here
这件事刚刚发生在我身上,我是从谷歌来到这里的!我设法解决了这个问题,所以下次我遇到它时将在这里添加解决方案!
只需删除可能位于
C:\ProgramData\Adobe\InDesign\Version 8.0\en_GB\Scripting Support\8.0
路径下的Resources for Visual Basic.tlb
文件即可然后以管理员身份打开 InDesign 并等待其运行。我发现 C# 应用程序在下次运行时挂起,因此必须关闭 InDesign,并让 C# 自行打开它!例子:
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 ofC:\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: