There are several ways to "build" a document, i.e.: place products linked with a template i na document according to (or not accordig to) rules provided by a page template. Pages can be generated
The minimal information required to build a page is
In most situations, calling build
is the easiest and fastest solution to generate pages:
import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import com.priint.comet.metadata.item.Item; import com.priint.comet.metadata.item.ItemFactory; import com.priint.comet.renderer.Renderer; import com.priint.comet.renderer.OpenedDocument; import com.priint.comet.renderer.exception.RendererException; public class Build { private Renderer renderer = new Renderer(); public static final String[][] PRODUCT_IDS = { {"1", "0", "0", "product.308"}, {"1", "0", "0", "product.265"}, {"1", "0", "0", "product.262"}, {"1", "0", "0", "product.266"}, {"1", "0", "0", "product.263"}, {"1", "0", "0", "product.184"}, {"1", "0", "0", "product.152"}, }; public static final int PAGE_TEMPLATE_ID = 13; public static final int ITEM_TEMPLATE_ID = 2; public void buildItems() { // setup list of items to build: List<Item> items = new ArrayList<>(); // add a page template at first position items.add(ItemFactory.createPageTemplate(PAGE_TEMPLATE_ID)); for (String[] id : PRODUCT_IDS) { items.add( ItemFactory.createItem( Integer.parseInt(id[0]), Integer.parseInt(id[1]), Integer.parseInt(id[2]), id[3], ITEM_TEMPLATE_ID)); } // apply this list to an existing document: try (OpenedDocument document = renderer.openDocument( "DSN", new TmpCopyFromPath(Paths.get("/path/to/original/doc.w2ml")))) { // will append at last spread document.build(items); // force starting at first spread document.build(items, 0); // force starting at first spread on the page element nearest to 17.9 / 32.6 document.build(items, 0, 17.9, 32.6); } catch (RendererException e) { // exceptions during build // rendering } catch (Exception e) { // exceptions during auto-close } } }