Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#
Article

Accessing Adobe InDesign CS COM Objects from .NET

Rate me:
Please Sign up or sign in to vote.
3.00/5 (11 votes)
9 Nov 2005CPOL 82.6K   14   17
An article showing how to access Adobe InDesign CS COM objects from .NET

Introduction

This article shows how to access Adobe InDesign CS COM objects from .NET.

Background

I needed to make an application that read product information from a database and inserted it in an Adobe InDesign template to create a catalog ready for printing. There is not much information about this subject to be found on the Internet, so I thought I might share this article with you.

Note: Adobe InDesign CS and the InDesign SDK need to be installed on the development computer.

Using the Code

Create a new project in Visual Studio and make a reference to COM object 'Adobe InDesign CS Type Library'. The following code creates an instance of the InDesign application and gets the first textframe on the first page.

C#
// 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";

To create an instance of the InDesign COM object, I use the following code snippet:

C#
/// <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;
}

History

  • 9th November, 2005: First publication

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMuch simpler way to insert DB content into InDesign document Pin
Gabriel Glowacki9-Nov-19 5:12
professionalGabriel Glowacki9-Nov-19 5:12 
Thanks for this valuable article Smile | :)
Years ago I have the same goal. To make a catalog (of books) from Access Database. I've used Word Mail Merge mechanism to get records into formatted Word document. Than the only thing to do was an import it into InDesign.
I use InDesign (Illustrator and Photoshop) COM objects for many tasks now. For example creating and saving documents based on parameters from database but these are much simpler tasks (in my opinion) than making such COM "connection" only for preparing a catalog from database.

Much more interesting and useful for everyday graphic preparation is to make full document/file manipulation tool based on database. Preparing a simple stand advertisement products consisting of three separate parts requires preparation over 20 files (part graphics, cut paths, layout etc). This gives huge number of files in normal production even small advertisement firm. This is my target. Many of the elements of such file management system I have already developed (I am using them in everyday work), but it requires a lot of work to get them into independent program. Still they are related on full MS Access license.
QuestionError de conversión Pin
Member 1415852418-Mar-19 5:15
Member 1415852418-Mar-19 5:15 
Questionc# Indesign.pageitem? err Pin
adcny22-Aug-16 20:32
adcny22-Aug-16 20:32 
QuestionWeb Application Pin
qadirv9-May-12 2:27
qadirv9-May-12 2:27 
Questionhi Pin
dinakar9026-Mar-12 4:22
dinakar9026-Mar-12 4:22 
Questionend of statement expected error Pin
dinakar9026-Mar-12 4:20
dinakar9026-Mar-12 4:20 
Generalhi Pin
Hal201230-Nov-10 18:36
Hal201230-Nov-10 18:36 
Generalconverting indesign EPS file to indesign Pin
vidyas198215-Aug-10 22:39
vidyas198215-Aug-10 22:39 
GeneralFormatting text Pin
Christian Gad13-Jan-10 22:00
Christian Gad13-Jan-10 22:00 
GeneralGreat topic Pin
inwi23-Nov-09 15:27
inwi23-Nov-09 15:27 
GeneralThanks Pin
Gary Stafford7-Feb-07 15:00
Gary Stafford7-Feb-07 15:00 
QuestionC# and InDesign Pin
K. Zimny12-Sep-06 9:31
K. Zimny12-Sep-06 9:31 
AnswerRe: C# and InDesign Pin
elmer_torensma12-Sep-06 21:10
elmer_torensma12-Sep-06 21:10 
GeneralRe: C# and InDesign Pin
pasaulis4-May-07 2:53
pasaulis4-May-07 2:53 
GeneralRe: C# and InDesign Pin
amin_khan6-Oct-07 21:24
amin_khan6-Oct-07 21:24 
QuestionRe: C# and InDesign Pin
Member 36519878-Dec-08 21:36
Member 36519878-Dec-08 21:36 
AnswerRe: C# and InDesign Pin
Hal201230-Nov-10 19:15
Hal201230-Nov-10 19:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.