Monthly Archives: February 2008

How to automate Adobe InDesign CS3

1. Locate Resources for Visual Basic.tlb in C:\Documents and Settings\All Users\Application Data\Adobe\InDesign\Version 5.0\Scripting Support\5.0 folder.

2. Open command prompt and execute:

TlbImp.exe "Resources for Visual Basic.tlb" /out:Interop.InDesign.dll

TlbImp.exe is located in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin folder on my machine. This will generate Interop.InDesign.dll file. This is an interop assembly.

3. Add reference to Interop.InDesign.dll to your project.

4. Use this code:

using System;
using InDesign;

namespace HelloInDesign
   class Program
      static void Main(string[] args)
         object missing = Type.Missing;
         Type type = Type.GetTypeFromProgID("InDesign.Application.CS3");
         if (type == null)
            throw new Exception("Adobe InDesign CS3 is not installed");
         _Application app = (_Application)Activator.CreateInstance(type);
         Document document = (Document)app.Documents.Add(true, missing);
         Page page = (Page)document.Pages[1];
         TextFrame textFrame = page.TextFrames.Add(missing,
            idLocationOptions.idUnknown, missing);
         textFrame.GeometricBounds = new string[] { "6p", "6p", "24p", "24p" };
         textFrame.Contents = "Hello from .Net!";