Overview

Which Interface should I choose?

There are basically two ways to access priint:comet functionality in a Server environment:

  1. Connect to a Rendering Server (priint:pdf renderer or InDesignServer) via the SOAP Interface provided by the CometServer application.
  2. Directly connect to InDesignServer using the Scripting DOM extensions. This interface is mainly intended for internal use!

Connecting via the CometServer SOAP interface (1) is the recommended way and will also cover basic aspects of authentication, session handling, document management and load balancing. Usage examples are included in this document, see below.

For a full API reference see CometWhiteboard class reference delivered with the PubServerSDK (included in the Ison workspace). A Java SOAP client based on the JAX-WS reference implementation (priintwsclient.jar) is also included in the CometServer4SDK.

The Scripting interface (2) is especially useful for test scripts, to access the full priint:comet plug-in functionality with the least effort for application environment. This interface is not recommended for application integration. With this interface, you can address InDesignServer only (not priint:pdf renderer). The InDesignServer Scripting DOM is exposed in JavaScript, VBScript, AppleScript and (via a generated CORBA client) Java. The priint:comet extensions can also be addressed via a SOAP WebService interface.
For a full reference see the InDesignServer scripting reference included in the priint:comet plug-in documentation. Please note, that we do not provide any further support for the Scripting interface (2).

The examples below refer to the CometServer SOAP interface and Java. Most of them can easily be adapted for the Scripting DOM interface and other programming platforms.

More Information

More examples can be found in priintwsclient.jar (compiled Java classes and source code) included in the PubServerSDK.
If you need development support, please contact support@priint.com.

Requirements

To use the CometServe SOAP interface (1), you need a CometServer 3.4 installation with InDesignServer and priint:comet InDesignServer plug-ins or or priint:publishing server installation with CometServerLight Plugin and priint:pdf renderer resp. priint:comet InDesignServer plug-ins.

Integration of InDesignServer is supported in any version of priint:publishing server / CometServer 3.4, priint:pdf renderer requires priint:publishing server version 4.1 or later.

Depending on the client platform you may also need a compiler or interpreter and additional libraries to support SOAP.

To use the Scripting DOM extension (2), you need print:comet InDesignServer plug-ins and a client application (such as ExtendScript Toolkit to run JavaScript or the AppleScript Editor for AppleScript) to execute your scripts.

In both cases, you need a fully setup Comet Project, i.e. Templates, Placeholders, application data etc.

Configuring Renderers for API Use

To seperate long running tasks like generating pages from tasks, which require fast response times, rendering server instances can be assigned to a certain type.

To call PDF Renderer or InDesignServer through the CometWhiteboard API, you need at least one instance configured as MIXED or as PRINTONDEMAND.

Rendering servers (i.e. InDesignServer and priint:pdf renderer) instances are configured in two tables in the comet_admin database. These tables are named indesignserver resp. indesignserverinstance, though they are used for priint:pdf renderer configuration also.

Rendering Server Configuration

There should be at least two preconfigured server entries in the priint:suite > Administration > Preferences > AdminDB property > Indesign servers node. Actually we do not configure physical servers here, but only server types (LOCAL, REMOTE etc.), see screenshot below.
If for any reason these nodes do not exist in your installation, you have to edit the indesignserver table in the comet_admin database (e.g. using MySQL Workbench, Microsoft SQL Server Management Studio or similar tools).

SELECT * FROM comet_admin.indesignserver;
should output something like
+----------+----------------+----------------+
| SERVERID | SERVERNAME     | SERVERPROTOCOL | 
+----------+----------------+----------------+
| 2        | Remote Server  | REMOTE         |
| 3        | Offline Server | COMETOFFLINE   |
+----------+----------------+----------------+
If these entries are missing, add at least the REMOTE entry, e.g. using this SQL statement:
INSERT INTO comet_admin.indesignserver (SERVERID, SERVERNAME, SERVERPROTOCOL) 
    VALUES (2, 'Remote Server', 'REMOTE');
In newer installation, you will find an entry for the priint:pdf renderer also:
+----------+----------------+----------------+
| SERVERID | SERVERNAME     | SERVERPROTOCOL | 
+----------+----------------+----------------+
| 4        | PDF Renderer   | PDFRENDERER    |
+----------+----------------+----------------+
You must restart glassfish / publishing servers to see the changes.

InDesignServer Instance Configuration

By opening the REMOTE server node, you should see instances configured for this server type (see screenshot).

If there are no or not enough instances, you have to add them to the comet_admin.indesignserverinstance table (e.g. using MySQL Workbench, Microsoft SQL Server Management Studio or similar tools).

SELECT * FROM comet_admin.indesignserverinstance;
should output something like
+------------+----------+--------------+-------------------+--------+-------
| INSTANCEID | SERVERID | INSTANCENAME | ENDPOINT          | ACTIVE | TYPEID ...
+------------+----------+--------------+-------------------+--------+-------
| 6          | 2        | Remote 01    | http://host:port/ | 1      | 2      ...
| ...        |          |              |                   |        |        
+------------+----------+--------------+-------------------+--------+-------

To add an instance, type something like

INSERT INTO comet_admin.indesignserverinstance
  (INSTANCEID, SERVERID, INSTANCENAME, ENDPOINT, ACTIVE, TYPEID, LOGIN, PASSWORD)
     VALUES
  (7, 2, 'Remote 02', 'http://host:anotherport/', 1, 2, '', '');
INSTANCEID must be unique (e.g. SELECT MAX(INSTANCEID) + 1), SERVERID must be the ID of the REMOTE entry in the indesignserver table.

Once created, the InDesignServer instances can be configured in the priint:suite administration console.

Settings for each instance are

Note: using dedicated credentials for each InDesignServer instance can be very useful when tracking problems in the Glassfish / publishing server log file.

priint:renderer Instance Configuration

Make sure, the indesignserver table contains an entry for the PDF Renderer server.

By opening the REMOTE server node, you should see instances configured for this server type (see screenshot).

If there are no or not enough instances, you have to add them to the comet_admin.indesignserverinstance table (e.g. using MySQL Workbench, Microsoft SQL Server Management Studio or similar tools).

SELECT * FROM comet_admin.indesignserverinstance;
should output something like
+------------+----------+--------------+-------------------+--------+-------
| INSTANCEID | SERVERID | INSTANCENAME | ENDPOINT          | ACTIVE | TYPEID ...
+------------+----------+--------------+-------------------+--------+-------
| 7          | 4        | PDF 02       | C:\dev\comet_pdf  | 1      | 2      ...
| ...        |          |              |                   |        |        
+------------+----------+--------------+-------------------+--------+-------

To add an instance, type something like

INSERT INTO comet_admin.indesignserverinstance
  (INSTANCEID, SERVERID, INSTANCENAME, ENDPOINT, ACTIVE, TYPEID, LOGIN, PASSWORD)
     VALUES
  (7, 2, 'Remote 02', 'http://host:anotherport/', 1, 2, '', '');
INSTANCEID must be unique (e.g. SELECT MAX(INSTANCEID) + 1), SERVERID must be the ID of the REMOTE entry in the indesignserver table.

Once created, the InDesignServer instances can be configured in the priint:suite administration console.

Settings for each instance are

Note: using dedicated credentials for each InDesignServer instance can be very useful when tracking problems in the Glassfish / publishing server log file.

Connecting with CometServer resp. priint:publishing server

To connect to CometServer via the CometWhiteboard SOAP interface, you need a SOAP client. The SOAP service is exposed via HTTP and described in a standard WSDL (Web Service description language) document and there are tools to generate SOAP clients (so called client stubs) available for almost any platform.* This WSDL document is named CometWhiteboard.wsdl and is included with the CometServer4SDK.

Solutions have already been developed in Java, C#, .Net, C++ and PHP. A Java client is included in this documentation. If required, Werk II can provide support to integrate the Comet WebServices in other platforms, please contact support@priint.com.

As Java is the most common client platform, the examples below refer to Java.

Client and Workspace Setup

In three steps:

  1. create a new empty Java project (e.g. in Eclipse create a plain Java Project)
  2. add the priintwsclient.jar library to your build path
  3. do some magic to bypass server WSDL validation (because time consuming and not necessary in this context) and to set the endpoint property, see code below
package com.priint.example;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

import javax.xml.namespace.QName;

import com.priint.comet.wsclient.whiteboard.CometWhiteboard;
import com.priint.comet.wsclient.whiteboard.CometWhiteboard_Service;

public class SoapExample {

  public static void main(String args[]) {
    // magic ...
    URL wsdlUrl = com.priint.comet.wsclient.whiteboard.CometWhiteboard_Service.class.getResource("/META-INF/CometWhiteboard.wsdl");
    // ... end of magic
    final CometWhiteboard_Service service = new CometWhiteboard_Service(wsdlUrl, new QName("http://whiteboard.service.comet.priint.com/", "CometWhiteboard"));
    CometWhiteboard port = service.getCometWhiteboardPort ();
    // set service endpoint property, sort of magic too:
    final Map<String, Object> context = ((javax.xml.ws.BindingProvider)port).getRequestContext();
    context.put (javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://my.server.tld:port/CometServerSOAP/CometWhiteboard");
  }
}     
That's it. You are connected to CometServer.

Of course, you have to replace the schema, host and port part in the endpoint URL by the actual address of your server (but keep the path part of the URL), but that's all that has to be changed to establish a real connection to your server.
The CometWhiteboard port object provides all methods described in the CometWhiteboard interface and will do all necessary work to send and receive data to and from your server.

Login

Most methods of the CometWhiteboard interface (except for login) require a sessionID as first parameter.*
To get a sessionID (i.e. initialize a session) you must login first:

package com.priint.example;

// ... (see above)
import com.priint.comet.wsclient.whiteboard.SessionInfo;

public class SoapExample {

  public static void main(String args[]) {
    // ... (see above)
    try {
      SessionInfo session = port.connectionLogin("username", "password", "project-name");
      String sessionID = session.getSessionID();
      System.out.println(sessionID);
    } catch (CometException_Exception e) {
      e.printStackTrace();
    }
  }
}
      

 * Why do we use this old-style parameter based session handling? In the behalf of interoperability. It's simply the solution which will cause least problems with any framework, internet proxy, firewall or whatsoever. It's not the most elegant or sophisticated, but the most robust and compatible solution.

Logout

When you're done, you should logout. This will allow the server to perform cleanup tasks, e.g. delete intermediate session files etc.

package com.priint.example;

// ... (see above)

public class SoapExample {

  public static void main(String args[]) {
    // ... (see above)
    try {
      // ... (see above)
      port.connectionLogout(sessionID);
    } catch (CometException_Exception e) {
      e.printStackTrace();
    }
  }
}
You can reuse a session for further jobs. In this case, please remind, that the session will expire after 12 hours. So you should add something like this to your code:
package com.priint.example;

// ... (see above)
import javax.activation.DataHandler;
import com.priint.comet.wsclient.whiteboard.CometException;

public class SoapExample {

  public static void main(String args[]) {
    // ... (see above)
    try {
      // ... (see above)
      // just what your program was supposed to do:
      DataHandler pdf = port.createProductPDF(sessionID, masterdocName, recordID, templateID, pdfProfile, options);
    } catch (CometException_Exception e) {
      CometException cause = e.getFaultInfo();
      if (cause.getErrorCode() == com.priint.comet.wsclient.util.ErrorCodes.INVALID_SESSION) {
        // session invalid or expired. 
        // Login again to initialize a new session and repeat request
        // ... 
      }
      e.printStackTrace();
    }
  }
}

Conclusion

If all this works, you're ready for the next step and you can start working with real priint::pdf renderer or InDesign documents.
Full working code for connecting, login and logout, including error handling for expired connections:

package com.priint.example;

import java.net.URL;
import java.util.Map;

import javax.xml.namespace.QName;

import com.priint.comet.wsclient.whiteboard.CometException;
import com.priint.comet.wsclient.whiteboard.CometException_Exception;
import com.priint.comet.wsclient.whiteboard.CometWhiteboard;
import com.priint.comet.wsclient.whiteboard.CometWhiteboard_Service;
import com.priint.comet.wsclient.whiteboard.SessionInfo;

public class SoapExample {

  public static void main(String args[]) {
    URL wsdlUrl = com.priint.comet.wsclient.whiteboard.CometWhiteboard_Service.class.getResource("/META-INF/CometWhiteboard.wsdl");
    final CometWhiteboard_Service service = new CometWhiteboard_Service(wsdlUrl, new QName("http://whiteboard.service.comet.priint.com/", "CometWhiteboard"));
    CometWhiteboard port = service.getCometWhiteboardPort ();
    final Map<String, Object> context = ((javax.xml.ws.BindingProvider)port).getRequestContext();
    context.put (javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://my.server.tld:port/CometServerSOAP/CometWhiteboard");
    try {
      // start session
      SessionInfo session = port.connectionLogin("username", "password", "project-name");
      String sessionID = session.getSessionID();
      
      // real work is done HERE
      // ...
      
      // finally end session
      port.connectionLogout(sessionID);
    } catch (CometException_Exception e) {
      CometException cause = e.getFaultInfo();
      if (cause.getErrorCode() == com.priint.comet.wsclient.util.ErrorCodes.INVALID_SESSION) {
        // session invalid or expired. 
        // Login again to initialize a new session and repeat request
        // ... 
      }
      e.printStackTrace();
    }
  }
}

Choose Renderer

Many operations are supported by InDesignServer and priint:pdf renderer. Usually requests are sent to the next available rendering instance - regardless of the type.
If you want to address a certain type of renderer, you can state this for the current session:

package com.priint.example;

// ... (see above)
import com.priint.comet.wsclient.whiteboard.SessionInfo;

public class SoapExample {

  public static void main(String args[]) {
    // ... (see above)
    try {
      SessionInfo session = port.connectionLogin("username", "password", "project-name");
      String sessionID = session.getSessionID();
      // possible values:
      //     Renderer.PDFRENDERER
      //     Renderer.INDESIGNSERVER
      //     Renderer.ANYTYPE
      port.connectionSetRenderer (sessionID, Renderer.PDFRENDERER);
      System.out.println(sessionID);
    } catch (CometException_Exception e) {
      e.printStackTrace();
    }
  }
}

Documents

Beside special use cases (e.g. generate a product preview based on a template, using the server defaults for new documents), you always need a master document or document template, if you want to generate pages.

This can be an InDesign document, which was uploaded either as a master document or directly as the document template for a specific publication node.

For the PDF renderer, you will use W2ML documents, which can be obtained this way:

Documents on the server can be referred in several ways. Generally you refer to a document by name or a unique document ID. This name or document ID is bound to a physical priint:pdf renderer or InDesign document on the server file system.
In this documentation, we only cover three four very common use cases:

  1. a priint:pdf renderer or InDesign master document uploaded with the publication planner
  2. an arbitrary file on the server file system
  3. a document created "from scratch"
  4. a document managed by the publication planner

Master Document uploaded with the priint:planner

When uploading a master document, you must provide a unique name. In certain methods, you can refer to this master document using this name. In the latest publication planner shipped with priint:publishing server 4.0.5, you can also provide a masterdocument label when uploading a masterdocument and refer to the label in API methods.

Example:

// the name of my master document
String masterDocumentName = "myMasterDocument.indd";

// the ID for the temporary copy, null means: let server determine unique ID (generally recommended)
String tmpID = null;

// this creates a temporary copy, which will be deleted when session expires:
tmpID = port.copyMasterdocument(sessionID, masterDocumentName, tmpID);

// ... do some processing, see examples below ...

// finally download document
DataHandler document = port.documentDownload(sessionID, tmpID);
        

Arbitrary File on the Server File System

You do not want clients to access arbitrary files on the server file system, therefore files must be registered before and after that can be refered using a unique document ID.
Registering files can be restricted to certain paths and / or certain user accounts, for details see the Installation Guide or contact support@priint.com.

// the ID for this document, null means: let server determine unique ID (generally recommended)
String newDocumentID = null;

// depending on your configuration,  "/path/on/server/" probably must be registered as
// a repository root, otherwise this method call will fail:
newDocumentID = port.documentRegister(sessionID, newDocumentID, "/path/on/server/document.indd");

// ... do some processing, see examples below ...
      

The second example shows handling of arbitrary files using a w2ml document for priint:pdf renderer:

// the ID for this document, null means: let server determine unique ID (generally recommended)
String newDocumentID = null;

// w2ml file exported from a InDesign document:
newDocumentID = port.documentRegister(sessionID, newDocumentID, "/path/on/server/document.w2ml");

// when processing this document, we certainly want to use the pdf renderer:
port.connectionSetRenderer (sessionID, Renderer.PDFRENDERER);

// .. etc

Document created from Scratch

You can also just use InDesignServer to create a new document. Various setup options can be passed in the "option" parameter, for details see the Options reference:

// this will create a new document, ID is provided by server
String newDocumentID = port.documentCreate(sessionID, null, "height:500pt;width20pt;");
      
A more sophisticated example: we first register a not yet existing file using a certain document ID. When calling documentCreate, this location will be used to save the file:
// register a not-yet-existing file with a certain document ID
String documentID = port.documentRegister(sessionID, "myDocumentID", "/Volumes/InDesignDocuments/work/myDocument.indd");

// create a document using this document ID
port.documentCreate(sessionID, documentID, "");

// save ...
port.documentSave(sessionID, documentID);

// and close. 
// It's good practice to close documents when done with processing, though 
// documents will be closed automatically, when the session is finished or expires
port.documentClose(sessionID, documentID);
      

Document managed by priint:planner

Documents in the publication planner are refered by their document ID.
This ID is available in many programming environments: in priint:comet publication scripts (implemented in cscript) as the global variable gDocument, in the document as an attribute of the XML root element of the document namend documentId and, consequently, can also be used to refer documents managed in the publication planner in Java client application.

Once you know the ID of the document you want to process, it is very easy to access this document in a client application:

String documentID = "67110123";
port.documentOpen(sessionID, documentID);
// etc.

Conclusion

You probably got the idea.
Of course, more combinations of the methods shown above are possible and you will find more document related methods in the CometWhiteboard class reference. If in doubt, which methods best suit your business requirements, please contact support@priint.com.

Create PDFs and Previews

PDF for one Product

You can place a single product and create a PDF in one go using the createProductPDF method:

// can be null also. In this case, a new document will be created
String masterDocumentName = "myMasterDocument.indd";

// RecordID consists of 4 parts: three numerical IDs and one "StringID"
// Values and meaning of these IDs depend on your environment
RecordID recordID = com.priint.comet.wsclient.util.Utils.createRecordID(new String[] {"1", "0", "0", "RecordStringID"});

// ID of the template (aka "pageitem")
int templateID = 12345;

// name of pdf profile. Leave empty for default profile 
String pdfProfile = "";

// various options, see options reference for details 
String options     = "";

// build and create PDF in one go
DataHandler pdf = port.createProductPDF(sessionID, masterDocumentName, recordID, templateID, pdfProfile, options);

// save result to local file
com.priint.comet.wsclient.util.Utils.saveBytes("/destination/path/out.pdf", com.priint.comet.wsclient.util.Utils.readAllBytes(pdf.getInputStream()));
      

PDF for several Products

To generate a PDF for a list of products, use the createPDF method.
Products are defined in a very simple XML format: the name of the root node must be <items>, each product is defined in a <item> element and must consist at least of the following information:

You do not have to (and actually should not) define namespaces, xml version, encoding etc.
String xml = "<items>\n";

// each product is an "item" in the xml.
// 1st product:
xml += "<item>\n" +
      "<ID>1</ID>\n" +
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID>RecordStringID</stringID>\n" +
      "<pageitemID>12345</pageitemID>\n" +
    "</item>";

// 2nd product:
xml += "<item>\n" +
      "<ID>2</ID>\n" +
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID>RecordStringID2</stringID>\n" +
      "<pageitemID>12345</pageitemID>\n" +
    "</item>\n";

// etc.
xml += "</items>";

javax.xml.transform.Source itemsXML = com.priint.comet.wsclient.util.XML.createXMLSource(xml, "items.xml");

DataHandler pdf = port.createPDF(sessionID, masterDocumentName, itemsXML,
                                 com.priint.comet.wsclient.whiteboard.Renderer.INDESIGNSERVER, pdfProfile, options);
      
Using this method and the items XML, you can also define a page template or force page breaks by inserting page template definitions in the list:
String xml = "<items>\n";

// start with this page template: 
xml += "<item>\n" +
      "<type>pagetemplate</type>\n" + 
      "<ID>1685</ID>\n" +               // ID of the page template
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID></stringID>\n" +       // empty
      "<pageitemID></pageitemID>\n" +   // empty
    "</item>";

// 1st product:
xml += "<item>\n" +
      "<ID>1</ID>\n" +
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID>RecordStringID</stringID>\n" +
      "<pageitemID>12345</pageitemID>\n" +
    "</item>";

// force page break after first product: 
xml += "<item>\n" +
      "<type>pagetemplate</type>\n" + 
      "<ID>1685</ID>\n" +               // ID of the page template
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID></stringID>\n" +       // empty
      "<pageitemID></pageitemID>\n" +   // empty
    "</item>";

// 2nd product:
xml += "<item>\n" +
      "<ID>2</ID>\n" +
      "<ID2>0</ID2>\n" +
      "<ID3>0</ID3>\n" + 
      "<stringID>RecordStringID2</stringID>\n" +
      "<pageitemID>12345</pageitemID>\n" +
    "</item>\n";

// etc.

xml += "</items>";
      

Preview for one Product

Just like creating PDFs, you can also create previews in various formats:

// resolution in dpi
double resolution = 300.0;

// creates a JPEG with default quality settings
DataHandler preview = port.createProductPreview(sessionID, masterDocumentName, recordID, templateID, resolution, options);
      
Image format can be set in the "options" string:
// settings suitable for web...
String options = "format:png;transparency:high;add-alpha:true;";

// resolution in dpi
double resolution = 72.0;

// creates a JPEG with default quality settings
DataHandler preview = port.createProductPreview(sessionID, masterDocumentName, recordID, templateID, resolution, options);
      

Generate InDesign Document

In case you want to keep the processed InDesign file, you can generate pages using one of the build methods.
Example:

// use this document
String documentID   = "myTargetDocument";

// start building at spread 0
int spreadIndex   = 0;

// the method returns the number of pages generated
int numberOfSpreadsGenerated = port.spreadBuild(sessionID, documentID, spreadIndex, itemsXML, options);
      
Another example: create a temporary copy of a masterdocument, place some products, create preview and pdf and download the generated document:
// create a temporary copy of a master document
String tmpDocumentID   = port.copyMasterdocument(sessionID, masterDocumentName, null); 

// start building at spread 0
int spreadIndex   = 0;

// we prefer to use the EXISTING pages
options += "prefer-existing-pages:true;";
      
// place products
int numberOfSpreadsGenerated = port.spreadBuild(sessionID, tmpDocumentID, spreadIndex, itemsXML, options);

// generate a preview for each spread
int spreadCount = port.documentGetSpreadCount(sessionID, tmpDocumentID);
for (int i = 0; i < spreadCount; ++i) {
  DataHandler preview = port.spreadGetPreview(sessionID, tmpDocumentID, i, resolution, options);
  // you might want to save the preview, see examples above ...
}

// generate a PDF
DataHandler pdf = port.documentGeneratePDF(sessionID, tmpDocumentID, pdfProfile, options);

// save and download InDesign document
port.documentSave(sessionID, tmpDocumentID);
DataHandler indd = port.documentDownload(sessionID, tmpDocumentID);
      

Finetuning

You may have noticed the options parameter, which allows to pass various options to almost all methods. These options are not absolutely required to execute a method, but can be extremely powerful.
Please refer to the Options Reference to find out, which options are available and useful for your requirements.

Running Scripts

You can run arbitrary cscripts with the rendering server, typically this is a build scripts (such as Document Planning or Publication Tree scripts).
To run scripts use the method

        	documentExecCScript (String sessionID, String documentID, int scriptID, String arguments);
        
The method returns a string, which can be defined in the target cscript. This way it is possible to pass values from the cscript / Renderer environment to Java / SOAP.

Scripts executed via the Server interface provide some additional environment variables:

The following example shows how to get spread previews and PDFs from a document generated with a custom build script. Compared to the Generate InDesign Document example from above, only very slight changes are required:
// create a temporary copy of a master document
String tmpDocumentID   = port.copyMasterdocument(sessionID, masterDocumentName, null); 

String arguments = "";

// the cscript ID
int scriptId = 67101234;

// execute cscript
String scriptResult = port.documentExecCScript(sessionID, tmpDocumentID, scriptId, arguments);

// generate a preview for each spread
int spreadCount = port.documentGetSpreadCount(sessionID, tmpDocumentID);
for (int i = 0; i < spreadCount; ++i) {
  DataHandler preview = port.spreadGetPreview(sessionID, tmpDocumentID, i, resolution, options);
  // you might want to save the preview, see examples above ...
}

// generate a PDF
DataHandler pdf = port.documentGeneratePDF(sessionID, tmpDocumentID, pdfProfile, options);

// save and download InDesign document
port.documentSave(sessionID, tmpDocumentID);
DataHandler indd = port.documentDownload(sessionID, tmpDocumentID);
        
Of course - in this case - we expect, that script 67101234 defines suitable code to generate pages.

Conclusion

This documentation only covers very basic - though, I hope, the most important - aspects of using the CometWhiteboard interface. Please refer to the CometWhiteboard API Reference delivered with the CometServer4SDK to find out, which methods best suit your business requirements.
If in doubt, please contact support@priint.com.

Appendix I: Options Reference 

Preface

All priint:comet server API operations need a set of certain parameters to be executed. Most commands have some optional parameters not necessarily required to complete the operation. These parameters can be passed in the options string, thus we keep the API simple for general uses and flexible for special requirements - however somewhat at the cost of syntactic strength.

This document should help you to find options appropriate for your needs and explain how and where they can be used.

Basics

Syntax

Options are passed as a list of key value pairs, elements separated by semicolons. A single option is a keword followed by colon and the value.

key:value;[key2:value;...]

The options string is parsed from left to right, latter statements therefore override former:

// width will be set to 534.0

String myoptions = "width:200.0;width:534.0;"

Some options are grouped and can either be set separately or in one pass:

// setting margins ...
String myoptions = "margin-left:20.;margin-top:20.;margin-right:20.;margin-bottom:20.";

// this would have the same effect
myoptions = "margin:20.;"; 

The override rules apply for grouped options as well:

// this will set all margins to 20pt except for margin-left, which will be 40pt
String myoptions = "margin:20.;margin-left:40.";

// ... but in this case the margin option will override margin-left too:
myoptions = "margin-left:40.;margin:20.;"; 

Values

Most options expect a value of a certain type. These are the supported types:
Type Description
int Integer
float a floating point number. Decimal seoarator is a dot.
boolean 0, !, false, off, no, none, nay, nope, omit, zero, dont, nothanks, never and skip (all case insensitive) will be interpreted as false, all other values as true .
String Strings can but dont have to be enclosed in double quotes. Note: layer names (in the layers option) MUST be quoted.
Enums / Sets Some options expect a string of a certain set. These values simply can be passed as a string (quoted or unquoted).

Example

	xmlversion:3.0;content:tagged,plain;svg:bbox;svg-text:full;layers:+"visible",-"hidden";

Reference

Global

userdata string path of the user / session data XML. all operations

General

page-scope string all, master or regular.
Operate on all, only master or regular page items. This applies to nearly all commands, except for elements.
xxGetCometGroups
xxGetElements
xxGetPlaceHolders
xxLoadPlaceholders xxSynncPlaceholders
xxUpdatePlaceholders
xxSetPlaceholderValue
xxSetPlaceholderImage
xxSetPlaceholderImagePath
xxGetPreview
xxGetPreviewOfClipping
xxGeneratePDF
createProductPreview
createProductPDF
createPDF

visibility string hidden, visible or all.
Operate on all, only visible or only hidden page items. Just like page-scope this does not apply for element commands.

Document Setup

pages int number of pages to create. documentCreate
pages-per-spread int number of pages per spread
reshuffle boolean allow page reshuffle spreadAddSpreads
spreadMoveSpreads
spreadDeleteSpreads
pageAddPages
pageMovePages
pageDeletePages

Document Format

size float [float] page size in pt, either width height or one value for both settings documentCreate
documentSetup
execTemplate
createProductPreview
createProductPDF
createPDF
width float page width in pt
height float page height in pt
margin float page margins
margin-top float top margin
margin-bottom float bottom margin
margin-left float left margin
margin-right float right margin
margin-outer float outer margin
margin-inner float inner margin
margin-outsideright float outside right margin
margin-insideleft float inside left margin
bleed float page / spread bleed
bleed-top float top bleed
bleed-bottom float bottom bleed
bleed-left float left bleed
bleed-right float right bleed
bleed-inner float inner bleed
bleed-outer float outer bleed
bleed-insideleft float inside left bleed
bleed-outsideright float outside right bleed
slug float page / spread slug
slug-top float top slug
slug-bottom float bottom slug
slug-left float left slug
slug-right float right slug
slug-inner float inner slug
slug-outer float outer slug
slug-insideleft float inside left slug
slug-outsideright float outside right slug

Build Offset

offset float [float] build offset x / y from left / top execTemplate
createProductPreview
createProductPDF
offset-x float build offset x from left of page
offset-y float build offset y from top of page

Place Products, Page Generation and Image Placement

layer string name of the target layer execTemplate
pagePlaceTemplate
spreadPlaceTemplate
pageBuild
pageBuildAt
spreadBuild
spreadBuildAt
cometGroupInsertBefore
cometGroupInsertAfter
cometGroupReplaceGroup
createProductPreview
createProductPDF
createPDF
snap-to-grid boolean snap to the next grid position execTemplate
pagePlaceTemplate
spreadPlaceTemplate
cometGroupInsertBefore
cometGroupInsertAfter
cometGroupReplaceGroup
snap-to-template boolean snap to the next page element
auto-load boolean load content after inserting templates, default: true
check-pagetype boolean check the page type when determining the correct template, default: true
build-prescript int use this prescript when building execTemplate
pagePlaceTemplate
spreadPlaceTemplate
xxBuild
xxBuildAt
build-pageitem int use this template when building
prefer-existing-pages boolean prefer existing pages when building, default: true
prefer-default-pageitem boolean prefer the default template when building, default: false
skip-empty-templates boolean skip products, when no template is provided (i.e.: no error will be thrown in that case), default: false
localize-masteritems boolean localize masteritems, default: false
auto-detect-type boolean auto detect type of source frame, when set to true content of text frames will be inserted instead of inlining. Default: false
apply-master boolean Apply masterpage as determined by the page template to pages (and following), default: true (for apply-master) and false (for apply-following)
This also affects pageSetTemplateID and spreadSetTemplateID
apply-following boolean
allow-doubles boolean Allow duplicate products, default: true xxBuild
xxBuildAt
documentSetItems
build-snippet-matches string [since v4.0.5, R8410] Prefer Comet snippets instead of building the products by templates. Snippets can be found by their document ID (or path, if no document ID is defined), by their template ID and/or by their product IDs. Any combination of the three IDs is allowed. (But not every combination is sensefull!).

Valid otptions:
   Never
   Combination of document, template, product
   strict (abbreviation for document-template-product)
   tolerant (abbreviation for template-product)
   fallback-allowed (Snippet too large? Use the template after all.)

Default : Never
Example : build_snippet-matches=tolerant, fallback-allowed
xxBuild
image-pos string Image placement, valid options:
top-centered
top-right
middle-left
middle-right
bottom-right
bottom-left
bottom-center
bottom-right
Default: place like existing.
elementSetImage
elementSetImagePath
image-scale string Image scaling, valid options:
none
fit-frame
fit-content
fit-content-width
fit-content-height
fit-frame-height
best
best-centered
Default: none

Comet Groups

combine-groups boolean combine CometGroups, i.e. also include subgroups, default true deleteCometGroup
xxMoveCometGroup
cometGroupResolveGroup
cometGroupJoinGroups

Previews

format string image file format: jpeg | png | tiff | gif | png spreadGetPreview
spreadGetPreviewOfClipping
pageGetPreview
pageGetPreviewOfClipping
cometGroupGetPreviews
elementGetPreview
spreadGetCometGroupsPreview
spreadGetElementsPreview
createProductPreview
adapterCreatePreview
scale float scaling x / y
scale-x float scaling x
scale-y float scaling y
greek-below float greek text below given font size (pt)
transparency string transparency quality: low | medium | high | maximum
quality string quality: low | good | great | excellent
encoding string jpeg encoding: baseline | progressive
color-space string color space: rgb | cmyk | lab | gray
antialiasing boolean antialiasing, default true
fullres boolean draw full resolution graphics, default true
add-alpha boolean Add alpha channel, default: depends on the image format (see above):
  • jpeg, gif: false
  • png, tiff: true
palette boolean (TIFF, GIFF): exact/adaptive | win | mac | web | none
interlaced boolean GIF only, default true
combine-groups boolean combine CometGroups, cometGroupGetPreviews only, default true
layers string layers to include in preview, see description below
extract boolean extract element or comet groups, i.e.: show only content of the given entity or inluce other frames. Default:
  • CometGroups, Elements: true
  • Spreads, Pages: false
compression int png only: image compression, default: 5

XML Options

xmlschema boolean Include XML Schema reference and namespaces, default true documentGetSpreads
xxGetCometGroups
xxGetPlaceholders
xxGetElements
xmlindent boolean Add linebreaks and indentations, default false
xmlversion float 2.9 or 3.0. The old 2.9 format is deprecated and is provided for compatibility reason only. Default: 3.0
content string list of text export formats, valid formats are plain, tagged or tagged-raw
svg string options for svg export: full | bbox | none
svg-group string options for CometGroups svg exports
svg-frame string options for frames / elements svg exports
svg-text string options for text / paragraphs svg exports
placeholders boolean include placeholder tags in text export
eval-sync boolean evaluate sync states of placeholders before export
mark-changes boolean mark placeholder changes, not yet supported
combine-groups boolean combine CometGroups, default true
oversets boolean calculate and include text overset / underset, default true
calc-sizes boolean Calculate sizes of groups or elements, all, relative and / or absolute.
Default: false
calc-sizes-rel boolean
calc-sizes-abs boolean
size-checktrans boolean check transparency when calculating sizes, default: true
size-checkmargins boolean check page margins when calculating sizes, default: true
size-allowholes boolean allow holes when calculating sizes, default: true
size-useclips boolean use image clipping paths when calculating sizes, default: true
size-ignore-overlaps boolean ignore overlaps when calculating sizes. Default: false
layers string layers to include in XML, see description below

Package

package-fonts boolean Include fonts in the document package, default true documentGetPackage
package-images boolean Include images in the document package, default true
package-color-profiles boolean Include color profiles in the document package, default true
package-hidden-layers boolean Include fonts, images and color profiles of hidden layers in the document package, default true
package-ignore-errors boolean Ignore document preflight errors, default true
package-report boolean Include instructions, default true
package-include-idml boolean Include IDML in the document package (only available from CC 2014), default false
package-include-pdf boolean Include PDF in the document package (only available from CC 2014), default false
package-pdf-profile string Name of the PDF profile to use when including PDF, default empty
package-folder-name string Name of the document package folder, default document name

Layers

The layers option is a comma seperated list of names of layers to show or hide, the option applies to XMLs, PDFs and previews. By default the document preferences are used, this is the status the document was last saved in InDesign Desktop and first opened in InDesignServer.

Each list elements starts with the operator + (show) or - (hide), followed by a layername in double quotes or the wildcard * (all layers), see the examples below.

Examples:

// Show all layers
layers:+*;

// show none
layers:-*;

// show default and some more
layers:+"layer-to-show-1",+"layer-to-show-2";

// show default and some less
layers:-"layer-to-hide-1",+"layer-to-hide-2";


// show specific layers only
layers:-*,+"layer-to-show-1",+"layer-to-show-2";

// show all but ...
layers:+*,-"layer-to-hide-1",-"layer-to-hide-2";

Note:

If your layer option has incorrect syntax an error will be thrown, but no error nor warning will be raised if you use invalid (not existing ...) layer names!

For internal Use only

There are some more options for internal use only. You shouldn't use them, but maybe you will stumble accross them when reading API logfiles:

move-absolute boolean x / y coordinates are absolute several (if not all)
move-relative boolean x / y coordinates are relative
documentId string the CometServer documentID of the current document
session string Session ID
internal-2ndrun boolean internal, failover handling

When reading the logs you will also notice that there is some more information passed along with the options string. This is part of the priint:comet server / InDesignServer protocol and subject to change without notice.

Appendix II: Error Codes

priint:cometserver Exceptions

INVALID_SESSION (1200)
Description: the session ID you used for an API request is not valid or session has expired.
Solution: Discard session and login again.

ACCESS_DENIED (1201)
Description: your account does not privilege you to access the requested ressource
Solution: there may be many reasons for this exception. One common fault is that the user tries to register a document outside of known repositories or you try to gather information from the server which is only available for administrators (like the list and status of all InDesignServer instances). Most likely this can be fixed by adding missing configuration or using a more privileged account.

ENDPOINT_NOT_FOUND (1223)
Description: this will be thrown if the communication endpoint of an InDesignServer instance (either URL or path to ior file) can not be found or resolved
Solution: check the InDesign Server configuration in your admin database, check the InDesign Server states.

ILLEGAL_ENDPOINT_STATE (1224)
Description: an InDesign Server is in an illegal stat
Solution: something went seriously wrong if you catch this exception. Most likely this was caused by a previous api / InDesignServer request, so dont bother trying to debug the piece of code where the exception occured. Check the InDesignServer status, plug-in logs and API logs.

NO_IDS_INSTANCE_AVAILABLE (1225)
Description: there is no InDesignServer instance available. Either none has been configured in your admin database or all instances are down / unreachable at the moment
Solution: check InDesignServer configuration and statuses

UNSUPPORTED_PROTOCOL (1226)
Description: the protocol provided for InDesignServer communication is not (yet) supported
Solution: use LOCAL for InDesignServer instances running on the priint application server machine (Corba will be used for communication in that case) or REMOTE for instances on remote machines (SOAP over HTTP will be used then).

DOCUMENT_NOT_OPENED (1227)
Description: the document is not opened. Either the InDesignServer istance responsible for requests regarding this document lost the reference to that document or your server is configured to disallow implicitOpen and you missed to call documentOpen before operating on the document
Solution: check the server configuration or your client application.

BINARYTRANSPORT_ERROR (1228)
Description: something went wrong while trying to pass binary data from InDesignServer to the client application
Solution: most likely this has something to do with unsufficient filesystem privileges. To avoid permission problems InDesignServer and priint:comet server should run under the same user account.

INVALID_PARAMETER_FORMAT (1229)
Description: a value of a certain type and range was expected but you provided something different
Solution: check the documentation for valid arguments. If the documentation appears to be wrong in that point we appreciate your feedback!

NOTYETIMPLEMENTED (1230)
Description: the API is available but the method is not yet implemented
Solution: this should not happen and if this is related to a documented API method we appreciate your feedback.

PATH_EXCEPTION (1232)
Description: a path required for an operation could not be setup. This could be a session temporary directory, the base directory for dataset default file storage etc
Solution: check configuration and filesystem privileges.

DOCUMENT_EXISTS (1233)
Description: you try to overwrite a document that already exists and your server policies require to delete that document first
Solution: check configuration or change the client application to reflect the server policies.

DOCUMENT_SAVE_ERROR (1234)
Description: a document could not be written to filesystem
Solution: most likely a filesystem privileges issue.

DOCUMENT_IN_USE (1235)
Description: a document cannot be deleted or overwritten because it is currently opened or checked out
Solution: check if the document is opened in other sessions (see status in the document table)

DOCUMENT_CLOSE_TIMEOUT (1236)
Description: a document could not be closed because the responsible InDesignServer instance was not available
Solution: check if the instance is running and maybe blocked by a long running job.

NOT_A_TMPFILE (1237)
Description: where a temporary document was expected the document provided was something else
Solution: you cannot apply this operation to that document

SERVER_STATE_EXCEPTION (1238)
Description: something went seriously wrong which could inidcate that the server is in an illegal state
Solution: refer to logfiles, most probably you will also have to check configuration (FS permissions etc.)

NO_DATABASE_CONNECTION (1239)
Description: an operation requires a database connection but there is none available
Solution: check the connection pool and jdbc resource configuration, check the persistence.props file.

COMET_SOAP_CLIENT_EXCEPTION (1240)
Description: a SOAP connection to a comet data provider is required but not available
Solution: at the moment there is nothing you can do.

DOCUMENT_NOT_REGISTERED (1241)
Description: a document ID could not be resolved. The document has neither been registered nor a publication system could provide a path for that document ID
Solution: if you think the document ID is correct check the document table in the admin database or your publication system if the document exists. Check if the session is connected to the correct dataset.

TARGET_INVOCATION_EXCEPTION (1243)
Description: this is a wrapper for exceptions thrown by third party modules and components or modules and components not in the standard distribution of comet server
Solution: refer to the documentation of the target system for further description and analysis.

REPOSITORY_NOT_FOUND (1244)
Description: a repository could not be found
Solution: does the requested repository exist?

DOCUMENT_LOCKED (1246)
Description: a document could not be used because it is currently locked
Solution: most probably the document is checked out by a client application.

PLEASE_CHECK_CONFIGURATION (4711)
Description: an operation required a resource that is not available in your configuration.
Solution: please check your configuration.

priint:comet ID plug-ins / priint:renderer Error Codes

Some of these exceptions are handled by priint:comet server so they will never be passed to the client application, though you might stumble accross them when reading server logs. The following list should help you to better track down error reasons.

COMET_CSCRIPT_ERROR (538624)
Description: a cscript returned an error.
Solution: see the plug-ins logfile, there you should find a hint where the error occured. If its caused by malformed syntax fix the script, if certain preconditions were not met when executing the script the error reason could as well be other misconfiguration or an error in the client application.

COMET_NO_LICENSE (538625)
Description: no license could be found for the plug-ins / Version you installed.
Solution: you should see a license order in the console output of the InDesignServer instance or in the plug-ins logfile. Send this order to license@priint.net, install the license file and restart InDesignServer.

NOT_YET_IMPLEMENTED (538626)
Description: the method requested is not yet implemented in the plug-in Version you are using.
Solution: if this is a documented API method and you have installed the latest priint:comet server and plug-in releases this should not happen.

INITIALIZATION_ERROR (538627)
Description: an error occured while initializing an InDesignServer instance
Solution: check the "CometEnvironment" folder. This should be a valid priint:comet XML folder. Could be a problem with any of the XML files, broken PDF and printer profiles, filesystem privileges.

DOCUMENT_NOT_FOUND (538628)
Description: a document could not be found
Solution: check, if the documentID / path resolution is correct. Is the path provided by priint:comet server correct? Is this path reachable from the machine / account InDesignServer is running on?

ILLEGAL_DOCUMENT_STATE (538629)
Description: the operation could not be applied to the document because it is in an unexpected state.
Solution: please refer to the plug-ins / API log what happened to that document before. Most probably you will also have to restert the InDesignServer instance the document is opened on.

DOCUMENT_OUTDATED (538630)
Description: a operation could not be applied to the document because the target (spread, page, cometgroup, element etc.) is not available anymore or does not allow this operation.
Solution: check if your client application reflects all changes made to a document

DOCUMENT_VANISHED (538631)
Description: a document expected to be opened on a certain instance is not opened anymore.
Solution: most probably this occured after several server restarts and the document statuses are out of sync. If possible you should consider to restart all services. Also check the entries in the comet_admin.adm_document table.

MALFORMED_XML (538632)
Description: a XML provided by the user is malformed.
Solution: this can be a setNotes or build operation. Check if the XML generated in your client application is correct.

INVALID_XML (538633)
Description: the XML is well formed but invalid.
Solution: see MALFORMED_XML.

PAGE_NOT_FOUND (538634)
Description: a target page could not be found.
Solution: is the page index provided correct (indexes are zero based)? Is the document structure information in your client application up to date?

INVALID_BOUNDS (538635)
Description: the bounds provided for a build operation (such as placeTemplate...) are incorrect.
Solution: check bounds.

SPREAD_NOT_FOUND (538636)
Description: a target spread could not be found.
Solution: is the spread index provided correct (indexes are zero based)? Is the document structure information in your client application up to date?

GROUP_NOT_FOUND (538637)
Description: a target group could not be found.
Solution: is the cometgroup ID provided correct? Is the document structure information in your client application up to date?

ELEMENT_NOT_FOUND (538638)
Description: a target element could not be found.
Solution: is the element ID provided correct? Is the document structure information in your client application up to date?

PLACEHOLDER_NOT_FOUND (538639)
Description: a target placeholder could not be found.
Solution: is the placeholder ID provided correct? Is the record ID provided correct? Is the document structure information in your client application up to date? Do the plug-ins use the correct database connection?

UNKNOWN_PDF_PROFILE (538640)
Description: a pdf profile name provided by the user could not be found in the InDesign prefs.
Solution: if it is a profile managed in the pdfprofiles.xml file (CometEnvironment): did InDesignServer initialize properly? You should see a list of loaded PDF profiles in the API log right after the setEnvironment call.

INVALID_TEMPLATE_ID (538641)
Description: the template ID provided is not valid.
Solution: check if the plug-in is connected to the correct database.

INVALID_SETUP_PARAMS (538642)
Description: the format or values provided for document setup are invalid.
Solution: check log files and client application.

CONNECTION_REQUIRED (538643)
Description: the operation requires a database connection but none is available.
Solution: this should not happen, check if you use the latest priint:comet server and plug-in releases and if your connection settings are correct.

UNRECOVERABLE_ERROR (538644)
Description: this error indicates serious problems with your InDesignServer installation. It will be thrown if no memory can be allocated or very basic InDesign operations (such as getting the spread list of a document) fail.
Solution: restart InDesign, if the problem still occurs check the installation.

BAD_POSITION (538645)
Description: coordinates provided are invalid.
Solution: refer to log file (api.log) for further hints.

INVALID_GRID_ID (538646)
Description: the grid ID provided is not valid.
Solution: check connection configuration, check client application.

GENERIC_BUILD_ERROR (538647)
Description: an error occured while building products.
Solution: refer to the plug-ins logfile for further hints. Could be broken configuration, missing images, filesystem issues etc.

ILLEGAL_OPTIONS (538648)
Description: the options provided for a command are invalid.
Solution: see the developer documentation, section “Options” for more information

UNKNOWN_SERVICE (538654)
Description: the service name provided for an ODBC connection is unknown.
Solution: check configuration, in particular the connections.xml file in your CometEnvironment folder. CheckDSN configuration.

AUTHORIZATION_ERROR (538655)
Description: the credentials provided for a database connection are invalid.
Solution: check configuration, in particular the connections.xml file in your CometEnvironment folder. CheckDSN configuration.

UNKNOWN_POOL (538656)
Description: a datapool could not be found.
Solution: check configuration, in particular the connections.xml file in your CometEnvironment folder.

CONNECTION_FAILED (538657)
Description: connecting to a database failed for any other reason but the errors described above.
Solution: check configuration, in particular the connections.xml file in your CometEnvironment folder. CheckDSN configuration.

SERVER_WAS_DOWN (538658)
Description: indicates, that an InDesignServer instance was shutdown since the time it was registered by priint:comet server.
Solution: this exception is handled by comet server, the InDesignServer instance will be reregistered.

UNKNOWN_EXPORT_FORMAT (538659)
Description: the export format provided is not valid.
Solution: at the time only "plain" and "tagged" and “raw” are supported.

UNKNOWN_MASTERPAGE (538660)
Description: the masterpage provided is invalid
Solution: provide a valid masterpage. Avoid special characters in masterpage names, in certain environments this can cause trouble.

ILLEGAL_ARGUMENT (538674)
Description: the format of a parameter does not match what was expected.
Solution: check if you use the latest releases of both priint:comet server and plug-ins.

InDesign Error Codes

Sometimes InDesign ErrorCodes are propagated to the client application. A full list of InDesign error codes can be found in the Adobe InDesign Products SDK documentation (docs/references/errorcodes.htm).
These are the most important:

FAILED (1)
Description: this appears to occur rather often
Solution: check the comet log file for a more detailed error description

kOpenDocFailedError (3588)
Description: document could not be opened - probably required plug-ins are missing or your InDesign version is too old
Solution: check file, InDesign and plug-ins (also other 3d party plug-ins) versions

kSaveDocFailedError (3590)
Description: saving a document failed. Most probably the document was converted from an older InDesign version or you don’t have write permissions on this file.
Solution: check file, InDesign and plug-ins (also other 3d party plug-ins) versions

kTooManyOpenFilesError (268)
Description: too many opened InDesign documents. Note: could also be opened templates.
Solution: change your client application to keep the numbers of opened files small. If this is caused by too many opened (Comet-) templates, please contact support@priint.com