TextFrame

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

Table of contents

First steps

Set up a TextFrame object and add it to a page object like that:

<?php 

use IDML\Content\TextFrame\TextFrame;

$textFrame = new TextFrame();

$page->addElement($textFrame);

If you want to set your own unique identifier, set up the TextFrame like that: new TextFrame('UniqueName');

Size and Position

Add a size and a position like that:

<?php

$textFrame
    ->setSize(100, 200)
    ->setPosition(10, 10)
;

Add Unit::MILLIMETERS as third parameter of each method if you prefer numbers in millimeters.

Adding text

Text is called Story and also stored in the Story object. You need to create one and add it then.

<?php

$textFrame->setParentStory($story);

Linking TextFrames

If you want to link multiple TextFrames to enable text content to float from one TextFrame into another, you need to do two things:

  1. Tell every TextFrame about the text content by calling $textFrame->setParentStory($story).
  2. Tell every TextFrame about the next TextFrame. This is important for letting InDesign know, in which TextFrames the content will float. $textFrameA->setNextFrame($textFrameB).

Here's a full example:

<?php

use IDML\Content\Story\CharacterStyleRange;
use IDML\Content\Story\LineBreak;
use IDML\Content\Story\ParagraphStyleRange;
use IDML\Content\Story\Story;
use IDML\Content\Story\Text;
use IDML\Content\TextFrame\TextFrame;

$story = new Story();
$story->addContent(
    new ParagraphStyleRange(
        null,
        new CharacterStyleRange(
            null,
            new Text('Hello World!'),
            new LineBreak()
        ) 
    )
);

$textFrameA = new TextFrame();
$textFrameA->setParentStory($story);

$textFrameB = new TextFrame();
$textFrameB->setParentStory($story);

$textFrameA->setNextTextFrame($textFrameB);

/** 
 * For sure, we need to add the textframes to a page 
 * and the story to our content object 
 */
$page
    ->addElement(
        $textFrameA,
        $textFrameB
    )
;

$content
    ->addStory(
        $story
    )
;