C# / .NETDevOpsMisc
C# / .NET
Accessing indesign server from C# via COM
Alexandru Puiu
Alexandru Puiu
September 24, 2012
2 min

I’ve done quite a bit of searching on InDesign Server, and according to the people at Adobe, C# isn’t “dynamic” enough for use with their API. But obviously, they were looking at Java documentation mislabeled C# or at some very old books. Anyway, a lot of things in their documentation are misleading, so I will attempt to get you started on the right path to using InDesign Server CS6 from C# via COM objects.

First thing I did was install the trial, which needs to be activated before the COM objects become available. There’s no message popping up anywhere telling you this, so unless you dig through the logs or run InDesign server from the command line, you’ll be left wondering.

The “Installation Instructions.pdf” file indicates you need to activate the 90-day trial with Adobe Provisioning Toolkit Enterprise Edition (APTEE), which in fact means Adobe Application Manager Enterprise (AAME), http://www.adobe.com/devnet/creativesuite/enterprisedeployment.html. You don’t need to create a distribution package, all you have to do is to go to the following location using command line “C:Program Files (x86)Common FilesAdobeOOBEPDAppEnterpriseutilitiesAPTEECS6” and run

"adobe_prtk --tool=StartTrial --leid=InDesignServer-CS6-Win-GM"

Your trial should now be activated. The COM libraries will be registered the first time you run InDesignServer.exe.

That wasn’t so hard, and you could’ve eventually figured it out, although it took me a few hours searching through discussion boards. Now the interesting part.

InDesign Server registers it’s COM objects when it starts up, and only makes them available in the context in which it was started up. I have yet to figure out why they do this, or how to get around it, but note that if you’re logged onto the computer with the same user twice and start it from one of them, the second instance can’t access the first, nor can it start its own InDesign instance. This information is very important if you’re trying to access it from a service or from within IIS.

Asuming everything went alright, you can now begin to create your project. You first need to add a COM reference to InDesignServer and then import

using InDesignServer;

Now to create the application and make a few calls.

InDesignServer.Application app;
InDesignServer.Document doc;
try
{
    app = new InDesignServer.Application();
    try
    {
        doc = app.Open(Path.Combine(@"C:temp", "inDesignDoc.indd"),
        InDesignServer.idOpenOptions.idDefault);
        doc.Export(InDesignServer.idExportFormat.idPDFType, Path.Combine(@"C:temp",
        "indesign.pdf"), Type.Missing, false, Type.Missing, false);
        doc.Close();
        doc = null;
    }
    catch {}
}
catch {}
// DO NOT CALL app.Quit(); This will quit your instance of the InDesign server, and leave you hanging.

To use InDesign Server from IIS 7, you’ll need to make the following changes.

  1. Configure the Application Pool to run as a specified user, and not as Network Service
  2. Set Load User Profile to True
  3. If you have a 64-bit OS, set Enable 32-Bit Applications to True
  4. And finally, start the InDesign server from the context of the IIS User.

In your Global.asax, on application start add the following:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        Process[] inDesignServerProc = Process.GetProcessesByName("InDesignServer");
        if (inDesignServerProc.Count() == 0)
        {
            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName =
            @"C:Program FilesAdobeAdobe InDesign CS6 Server x64InDesignServer.exe";
            process.StartInfo.Arguments = " noerrorlist";
            process.Start();
        }
    }
}

In about a minute (depending on the speed of your server), your InDesign Server will be accessible via COM. You’ll see the memory usage start low, then rise to about 108MB, and then drop down again and stabilize around 66MB, that’s when it’s ready for the first connection. Memory usage will vary, but it will likely stay around 200MB (my experience) after a few conversions.


Tags

utils
Alexandru Puiu

Alexandru Puiu

Engineer / Security Architect

Systems Engineering advocate, Software Engineer, Security Architect / Researcher, SQL/NoSQL DBA, and Certified Scrum Master with a passion for Distributed Systems, AI and IoT..

Expertise

.NET
RavenDB
Kubernetes

Social Media

githubtwitterwebsite

Related Posts

RavenDB Integration Testing
Using RavenDB in Integration Testing
December 24, 2022
2 min

Subscribe To My Newsletter

I'll only send worthwhile content I think you'll want, less than once a month, and promise to never spam or sell your information!
© 2023, All Rights Reserved.

Quick Links

Get In TouchAbout Me

Social Media