Click here to Skip to main content
Licence CPOL
First Posted 9 Nov 2005
Views 41,075
Bookmarked 12 times

Accessing Adobe InDesign CS COM Objects from .NET

By | 9 Nov 2005 | Article
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.

// 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:

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

About the Author

elmer_torensma

Web Developer

Netherlands Netherlands

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWeb Application Pinmemberqadirv2:27 9 May '12  
Questionhi Pinmemberdinakar904:22 26 Mar '12  
Questionend of statement expected error Pinmemberdinakar904:20 26 Mar '12  
Generalhi PinmemberHal201218:36 30 Nov '10  
Generalconverting indesign EPS file to indesign Pinmembervidyas198222:39 15 Aug '10  
GeneralFormatting text PinmemberChristian Gad22:00 13 Jan '10  
GeneralGreat topic Pinmemberinwi15:27 23 Nov '09  
GeneralThanks PinmemberGary Stafford15:00 7 Feb '07  
QuestionC# and InDesign Pinmemberkzimny9:31 12 Sep '06  
AnswerRe: C# and InDesign Pinmemberelmer_torensma21:10 12 Sep '06  
GeneralRe: C# and InDesign Pinmemberpasaulis2:53 4 May '07  
GeneralRe: C# and InDesign Pinmemberamin_khan21:24 6 Oct '07  
QuestionRe: C# and InDesign PinmemberMember 365198721:36 8 Dec '08  
AnswerRe: C# and InDesign PinmemberHal201219:15 30 Nov '10  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 9 Nov 2005
Article Copyright 2005 by elmer_torensma
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid