Workflow

This document is about the basic workflow of setting up and creating an IDML document.

Table of contents

Workflow

To create an IDML document, a Content object is needed, holding all the IDML components. Inside the Content object are all styles, spreads, pages, stories, and so on.

All classes can be initialized manually, but the recommended way is to use the Factory class. It will register the objects automatically in the Content object, which allows us to write less code. Here's an example:

Initialize the Factory at first:

<?php 

use BitAndBlack\IdmlCreator\Factory;

$factory = new Factory();

Create objects using the factory:

<?php

/** @var \BitAndBlack\IdmlCreator\Factory $factory */
$paragraphStyle = $factory->createParagraphStyle('Body Text')
    ->setPointSize(12)
    ->setLineHeight(14.4)
;

When your document is ready and every piece of content has been created, create a new writer object and give it your content:

<?php

use BitAndBlack\IdmlWriter\File\Tree;
use BitAndBlack\IdmlWriter\Writer;

/** @var \BitAndBlack\IdmlCreator\Factory $factory the factory, initialized above */
$writer = new Writer(
    $factory->getContent(), 
    new Tree()
);

Write the IDML content into a file:

<?php

/** @var \BitAndBlack\IdmlWriter\Writer $writer the writer, created above */
$writer->create('myFile.idml');

You can find more information about the Factory class and its create methods here.