从 .NET 访问 Adobe InDesign CS COM 对象





3.00/5 (11投票s)
一篇文章,展示如何从 .NET 访问 Adobe InDesign CS COM 对象
引言
本文展示了如何从 .NET 访问 Adobe InDesign
CS COM 对象。
背景
我需要创建一个应用程序,从数据库读取产品信息,并将其插入到 Adobe InDesign
模板中,以创建准备打印的目录。关于这个主题的资料在互联网上并不多,所以我认为可以与大家分享这篇文章。
注意:需要在开发计算机上安装 Adobe InDesign
CS 和 InDesign SDK。
Using the Code
在 Visual Studio 中创建一个新项目,并引用 COM 对象“Adobe InDesign
CS 类型库”。以下代码创建 InDesign
应用程序的实例,并获取第一页上的第一个 textframe
。
// create an InDesign instance
InDesign.Application app =
(InDesign.Application) COMCreateObject("InDesign.Application");
// get a reference to the current active document
InDesign.Document doc = app.ActiveDocument;
// get the first page
InDesign.Page page = (InDesign.Page) doc.Pages[1]; //1e pagina
// get the first textframe
InDesign.TextFrame frame = (InDesign.TextFrame) page.TextFrames[1];
// write contents of textframe
Console.WriteLine(frame.Contents.ToString());
// set contents of textframe
frame.Contents = "Andere content";
为了创建 InDesign
COM 对象的实例,我使用以下代码片段
/// <SUMMARY>
/// Creates a COM object given its ProgID.
/// </SUMMARY>
/// <param name="sProgID">The ProgID to create</param>
/// <RETURNS>The newly created object, or null on failure.</RETURNS>
public static object COMCreateObject (string sProgID)
{
// We get the type using just the ProgID
Type oType = Type.GetTypeFromProgID (sProgID);
if (oType != null)
{
return Activator.CreateInstance( oType);
}
return null;
}
历史
- 2005 年 11 月 9 日:首次发布