Content

This document is about how to set up and use a Content object.

Table of contents

Introduction

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.

Handling the contents manually

Create a Content object and give it some objects which are always needed:

<?php 

use IDML\Content;
use IDML\Content\BackingStory;
use IDML\Content\Container;
use IDML\Content\DesignMap;
use IDML\Content\Tag;

$content = new Content();
$content
    ->setBackingStory(new BackingStory())
    ->setContainer(new Container())
    ->setDesignMap(new DesignMap())
    ->setTag(new Tag())
;

Nearly all IDML components need to be added to the content object. This may look like that:

<?php 

use IDML\Content;
use Content\Style\ParagraphStyle;

$content = new Content();

$paragraphStyle = new ParagraphStyle('Body Text');
$paragraphStyle
    ->setPointSize(12)
    ->setLineHeight(14.4)
;

$content->add($paragraphStyle);

Using the Factory class

Instead of initializing the content object itself and transferring all IDML components manually, the factory class can also be used. It can be used to create IDML elements and automatically transfer them to the content object.

<?php 

use IDML\Factory;

$factory = new Factory();
$factory->createBackingStory();
$factory->createContainer();
$factory->createDesignMap();
$factory->createTag();

And to follow the example with the ParagraphStyle above:

<?php 

use IDML\Factory;

$factory = new Factory();

$paragraphStyle = $factory->createParagraphStyle('Body Text')
    ->setPointSize(12)
    ->setLineHeight(14.4)
;