Place template allows to place a single template linked with an item on arbitrary coordinates on a document spread. Contrary to build
, placeTemplate
The return value of placeTemplate
is the CometGroup Id of the newly created group.
The following example places a template linked with a product and gets the preview of this product:
import javax.activation.DataHandler; import com.priint.comet.metadata.DocumentMetadata; import com.priint.comet.model.RecordId; import com.priint.comet.renderer.Renderer; import com.priint.comet.renderer.OpenedDocument; import com.priint.comet.renderer.exception.RendererException; public class PlaceTemplate { private final Renderer renderer = new Renderer(); public void placeTemplate() { String w2ml = ""; int templateId = 2; String itemStringId = "product.309"; try (OpenedDocument document = renderer.openDocument( "DSN", new TmpCopyFromString(w2ml, W2MLDocumentType.class))) { int groupId = document.placeTemplate(-1, templateId, new RecordId(1, 0, 0, itemStringId), 0.0, 0.0); DocumentMetadata dmd = document.getMetadata(); DataHandler[] previews = dmd.getCometGroupPreviews(groupId); if (previews != null && previews.length > 0) { DataHandler itemPreview = previews[0]; // ... + save etc. } } catch (RendererException e) { // exception during rendering } catch (Exception e) { // exception during close } } }