Overview

The Java Rendering Library is designed to integrate in any environment and support several rendering engines. Therefore, some initialization steps are necessary, before the API can be used.

Startup Code

Prerequisites:

Initialization requires some steps:

  1. call Renderer.initialize once with optional configuration options
  2. register Named Connections (by calling Renderer.registerConnection)
  3. register one or more RendererFactories by calling Renderer.registerFactory
  4. (depending on rendering engine) additional code for renderer configuration

Example: Arbitrary Java Application

package com.priint.comet.renderer;
import com.priint.comet.renderer.exception.RendererException;
import com.priint.comet.renderer.pdf.PdfRendererFactory;
import com.priint.comet.renderer.pdf.W2MLDocumentType;

public class RendererInitialization {
  
  public static void main(String args[]) {
    try {
      // initialize core rendering SDK
      Renderer renderer = new Renderer();
      renderer.initialize();
      
      // register connections and projects
      renderer.registerConnection(NamedConnection.createXMLConnection("demo", "/path/to/xml/project/"));
      // ... + register further connections
      
      // register at least one rendering engine, in this case the embedded PDF renderer 
      renderer.registerFactory(PdfRendererFactory.class, W2MLDocumentType.class);
      
    } catch (RendererException e) {
      e.printStackTrace();
    }
  }
}

Example: PublishingServer Integration

In the PublishingServer (or any application server) environment, the @Startup method of a Singleton bean is probably a good place to implement renderer initialization:

package com.priint.pubserver.renderermanager;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import com.priint.comet.renderer.Renderer;
import com.priint.comet.renderer.exception.RendererException;
import com.priint.pubserver.plugin.PluginLibraryControl;
import com.priint.pubserver.plugin.PluginLibraryControl.PluginType;
import com.priint.pubserver.plugin.annotation.PubServerPluginLibrary;

@Singleton
@Startup
@PubServerPluginLibrary(
    id = "com.priint.pubserver.renderermanager",
    type = PluginType.SERVICE,
    vendor = "priint.com",
    version = "1.0"
)
public class PubServerRendererManagerLibrary extends PluginLibraryControl {
  @Override
  @PostConstruct
  public void startup() {
    super.startup();
    try {
      Renderer renderer = new Renderer();
      renderer.initialize( /* ... */ );
      renderer.registerConnection( /* ... */ );
      renderer.registerFactory( /* ... */ );
    }
    catch (RendererException e) {
      e.printStackTrace();
    }
  }
}
 

Initialization Parameters

The initialize method accepts a com.priint.comet.renderer.Configuration argument.
Configuration or derived classes wrap a collection of ConfigurationOption arguments, which can be setup like this:


Configuration configuration = Configuration.create()
  .set(ConfigurationOption.INSTALLATION_PATH, "C:\\renderer\\")
// + further options
; 
The following options are available in the core library (all defined in com.priint.comet.renderer.ConfigurationOption):

Benchmarking

The Java Rendering Library includes a simple benchmarking class. This is for testing purpose only, the results are not very accurate (particularly when run in multithreaded applications), but should provide at least a hint, how long certain rendering operations take.

((Renderer) renderer).initialize(
    Configuration.create()
    .set(ConfigurationOption.BENCHMARK, Boolean.TRUE)
  );:w

Measured times can be requested any time by calling

import com.priint.comet.renderer.internal.Bm;
String info = Bm.dump();

PDF Renderer

Initialization Parameters for PDF Renderer

The PDF Renderer supports the following additional configuration options (all defined in com.priint.comet.renderer.PdfConfigurationOption):

Initialization Example PDF Renderer

Renderer renderer = new Renderer();
renderer.initialize(
  Configuration.create()
  .set(PdfConfigurationOption.NATIVE_LIBRARY_PATH, "/usr/local/opt/priint/lib")
  .set(ConfigurationOption.BENCHMARK, true)
  .set(ConfigurationOption.CONFIG_PATH, "/usr/local/share/priint/config")
);

renderer.registerFactory(com.priint.comet.renderer.pdf.PdfRendererFactory.class);
// ...
Remark: the number of parallel pdf renderers (default: 4) is determined upon initialization and cannot be changed on Runtime.

FONT_POLICY

Font mapping can be specified on different levels:

The FONT_POLICY option allows to specify, which of these mappings may be used. If later a font cannot be found using a mapping according to the font policy, an Exception is thrown.

((Renderer) renderer).initialize(
    Configuration.create()
    .set(ConfigurationOption.PDFR_FONTPOLICY, 
                       Options.FontMapping.DEFAULT_MAPPING | Options.FontMapping.USER_MAPPING | 
                       Options.FontMapping.SYSTEM_FALLBACK_FONT)
);

Starting / Stopping PDF Renderers

There is no option and no need to start or stop particular pdf renderer instances. Up to 4 instances of the native library are loaded dynamically when first needed and unloaded, when the JVM terminates.

InDesign® Server

Initialization Parameters for InDesign® Server

Note: some of these options apply for single instances and should not be set as global configuratino options.

InDesign® Server supports the following additional configuration options (all defined in com.priint.comet.ids.InDesignServerConfigurationOption):

Initialization Example InDesign® Server

Renderer renderer = new Renderer();
renderer.initialize(
  Configuration.create()
  .set(InDesignServerConfigurationOption.REQUEST_TIMEOUT, 3600)
);
// register InDesignServer factory
renderer.registerFactory(com.priint.comet.renderer.ids.InDesignServerFactory.class);

//
// configure instances
// instances can also be added or removed later
//
InDesignServerConfiguration config1 = new InDesignServerConfiguration("http://remote.host:1234"); // unique endpoint
config1.set(InDesignServerConfigurationOption.INSTANCE_NAME, "hooky");

InDesignServerConfiguration config2 = new InDesignServerConfiguration("http://remote.host:5678"); // unique endpoint
config2.set(InDesignServerConfigurationOption.INSTANCE_NAME, "wooky");

InDesignServerFactory.addInstance(config1);
InDesignServerFactory.addInstance(config2);

Remark: the InDesign® server instance configuration can be changed on Runtime.

InDesign® Server Poolsize

The number of InDesign® Server instances controlled by this JVM / Java Rendering Library or the poolsize is determined by the number of configurations added to the InDesignServerFactory. In the example above, the poolsize (or number of running instances) would be 2.

The poolsize - like for pdf renderer - determines the maximum number of fully parallel Java rendering threads.

Note: InDesign® Server instance configurations must be unique.
The criteria for uniqueness is a unique endpoint

Important Note: one InDesign® Server must be connected to one JVM / Java Rendering Library only.
If several JVM / Java Rendering Library applications try to control the same InDesign® Server instance simultaneously, the behavior is undefined, but sooner or later this will most probably lead to errors or unexpected results.

Starting / Stopping InDesign® Server Renderers

InDesign® Server runs as an external application (in some environments even on an external host). Starting and stopping must also be controlled externally.
The minimum requirement for InDesign® Server instances is

For more information refer to the InDesign® Server configuration reference.