The Factory

This document is about the Factory class. Since IDML-Creator version 4.0, it is the recommended way to create objects: the Factory creates an object and registers it immediately in the Content object, which allows us to write less code.

Table of contents

How it works

Initialize the factory:

<?php

use BitAndBlack\IdmlCreator\Factory;

$factory = new Factory();

Every factory method returns the created object, already registered:

<?php

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

When your document is ready, give the writer the content that the factory filled:

<?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()
);

$writer->create('myFile.idml');

Reference of all create methods

Method Creates Where to learn more
getDesignMap() The DesignMap designmap
getPreference() The Preference preference
createMetaData() The MetaData metadata
createXmlTag(?string $uniqueId = null) The XMLTag designmap
createSpread(?string $uniqueId = null) A Spread pages
createMasterSpread(?string $uniqueId = null) A MasterSpread pages
createStory(?string $uniqueId = null) A Story typography
createColor(?string $uniqueId = null) A Color colors
createTint(ColorInterface $color) A Tint based on a color colors
createMixedInk(?string $uniqueId = null) A MixedInk colors
createFontStyle(FontFamily $fontFamily, string $fontStyleName) A FontStyle styling text
createParagraphStyle(?string $uniqueId = null) A ParagraphStyle styling text
createCharacterStyle(?string $uniqueId = null) A CharacterStyle styling text
createObjectStyle(?string $uniqueId = null) An ObjectStyle styling objects
createTableStyle(?string $uniqueId = null) A TableStyle tables
createCellStyle(?string $uniqueId = null) A CellStyle tables

The objects with an optional $uniqueId use a generated identifier when none is given — see unique identifiers.