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.
Initialization requires some steps:
Renderer.initialize
once with optional configuration optionsRenderer.registerConnection
)RendererFactories
by calling Renderer.registerFactory
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();
}
}
}
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();
}
}
}
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
):
INSTALLATION_PATH
: base folder of the installation. Used for several path calculations, defaults to parent folder of the priint-renderer-core-5.0-R35572.jar libraryCACHE_PATH
: base folder for caching. Currently used in PDF Renderer only, defaults to temporary folder provided by systemCONFIG_PATH
: base folder for configuration such as color profiles, font mapping, licenses. Currently used in PDF Renderer only, defaults to INSTALLATION_PATH + File.separator + "config"
FONT_POLICY
: how to map font names. Currently used in PDF Renderer only, defaults to use all available mappings. See example below.BENCHMARK
: enable benchmarking of renderer operations. See description below.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();
The PDF Renderer supports the following additional configuration options (all defined in com.priint.comet.renderer.PdfConfigurationOption
):
NATIVE_LIBRARY_PATH
: path of native libraries. Defaults to INSTALLATION_PATH + File.separator + "lib" + File.separator + "native" + File.separator + "linux" | "windows" | "mac"
LOAD_VCRUNTIME
: with some Java virtual machines it is necessary to explicitly load the VC runtime libraries. If initialization of the pdf renderer enginge fails a UnresolvedLinkException
, try setting this option to true. Defaults to false.POOLSIZE
: how many pdf renderer instances to run parallel. Maximum and default is 4. This is the number of fully parallel Java rendering threads. The library is capable to handle an arbitrary number of threads, but if the number of Java threads exceeds poolsize, threads may be blocked until the next rendering instance is free to process further requests.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 mapping can be specified on different levels:
((Renderer) renderer).initialize( Configuration.create() .set(ConfigurationOption.PDFR_FONTPOLICY, Options.FontMapping.DEFAULT_MAPPING | Options.FontMapping.USER_MAPPING | Options.FontMapping.SYSTEM_FALLBACK_FONT) );
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.
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
):
INSTANCE_ID
: (internal) ID of an instance. Calculated upon initialization of a particular instance. Cannot be set by userINSTANCE_NAME
: name of a particular instance. Should be set for a single instance.REQUEST_TIMEOUT
: request timeout. Can be set global or for a particular instance.CONNECT_TIMEOUT
: connect timeout. Can be set global or for a particular instance.ENDPOINT
: must be set and be unique for each particular instance.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.
InDesignServerFactory.addInstance
using an endpoint already added to the factory. In this case, the existing configuration will be updatedInDesignServerFactory.removeConfig
. The instance identified by endpoint
will be removed and no more jobs be delegated to this instance.InDesignServerFactory.addInstance
with a new / unique endpointThe 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.
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
-cometport
-cometcache