Creating a first text document

Creating an OpenDocument text document is really simple.

<?php
/**
* This script demonstrates how to create a new text document by
* adding a headline and a paragraph containing a link.
*/
require_once 'OpenDocument.php';

$doc = new OpenDocument();
$doc->createHeading('Welcome to OpenDocument!'1);
$p $doc->createParagraph('This script serves as a demonstration of PEAR\'s
OpenDocument package. You are invited to explore the capabilities of this
package and to read the API documentation available at '
);
$p->createHyperlink('pear.php.net''http://pear.php.net/package/OpenDocument');
$p->createTextElement('. Have fun!');

$doc->save('my-first-document.odt');
?>

After creating an OpenDocument instance, there are several methods available to create actual content; all of them are prefixed with create.

All of those methods return the created object. This object has already been inserted at the end of the document.

The newly created element may have some create*() methods of its own - a paragraph for example allows you to add links and additional text elements.

When you are done, call OpenDocument::save() with the filename as only parameter to store the document on disk.

Until version 0.1.2, only relative filenames are allowed.