Table of Contents

No Table of Contents available.

Writing IDML files with PHP

The IDML Writer for PHP is an open-source library, that allows creating and writing IDML files natively in PHP.

Installation

This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/idml-writer.

Usage

When creating a new instance of the Writer, you need to pass your content as first parameter and the IDML tree as second parameter:

<?php

use IDML\Writer\File\Tree;
use IDML\Writer\Writer;

$writer = new Writer(
    $myIDMLContent,
    new Tree()
);

The content which is $myIDMLContent in our example needs to be an object which implements the ContentInterface.

Since the structure of an IDML file is always the same, you don't need to customize or set up an own Tree object. But in case you want to you only have to implement the TreeInterface.

Create and store the IDML file by running create() like that:

<?php

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

Alternatively, if you want to get the content to store it by yourself or do whatever else, call getContent():

<?php

$idmlFileContent = $writer->getContent();

file_put_contents(
    'myFile.idml',
    $idmlFileContent
);

Content of an IDML

This library doesn't provide creating any IDML content. Creating content can be done by using the bitandblack/idml-creator library. Please note that this one has a private license and is not listed public. You can find more information about the IDML Creator library and its documentation here.