Search by

james2001 / odtbundle

james2001

Symfony bundle to fill ODT (OpenDocument Text) templates with the odtphp library

Package info

github.com/james2001/odtbundle

Type:symfony-bundle

pkg:composer/james2001/odtbundle

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

3.0.0 2026-12-01 07:46 UTC

This package is auto-updated.

Last update: 2026-12-01 09:28:06 UTC


README

CI Latest Stable Version Total Downloads License

Symfony bundle that fills ODT (OpenDocument Text) templates: variables, repeated segments and images, thanks to the odtphp library.

Which version should I use?

Bundle Branch PHP Symfony ODT library
3.x 3.x 8.1+ 6.4, 7.x, 8.x james2001/odtphp 2.x
2.x 2.x 7.2.5 – 8.x 4.4, 5.4 james2001/odtphp 1.x or 2.x
1.x 1.x 5.3.3 – 7.4 2.3 – 3.4 cybermonde/odtphp 1.x

You don't have to pick by hand: composer require james2001/odtbundle installs the newest version compatible with your PHP and Symfony versions.

This branch (3.x) is the active one, for Symfony 6.4, 7.x and 8.x applications.

Installation

composer require james2001/odtbundle

With Symfony Flex the bundle is enabled automatically. Otherwise add it to config/bundles.php:

return [
    // ...
    James2001\Bundle\OdtBundle\James2001OdtBundle::class => ['all' => true],
];

The PHP zip extension is used by default to read and write ODT files.

Usage

Write a template in LibreOffice with {tags}, and [!-- BEGIN name --] / [!-- END name --] around the part to repeat, then inject the factory:

use James2001\Bundle\OdtBundle\Factory;

class InvoiceController extends AbstractController
{
    public function download(Factory $odtFactory): Response
    {
        $odf = $odtFactory->createOdtObject($this->getParameter('kernel.project_dir').'/templates/invoice.odt');
        $odf->setVars('title', 'My document');

        $articles = $odf->setSegment('articles');
        foreach ($items as $item) {
            $articles->setVars('articleTitle', $item->getTitle());
            $articles->merge();
        }
        $odf->mergeSegment($articles);

        $file = tempnam(sys_get_temp_dir(), 'odt');
        $odf->saveToDisk($file);

        return $this->file($file, 'invoice.odt')->deleteFileAfterSend();
    }
}

odtphp 2.x expects UTF-8 strings in setVars(). The factory is also available as the public james2001_odt.factory service. See the odtphp README for every available method.

Upgrading from 2.x

  • PHP 8.1 and Symfony 6.4 are the new minimums, and james2001/odtphp 2.x is required. If your application ran on PHP 8.0 or older, it used odtphp 1.x: setVars() now expects UTF-8 by default instead of ISO-8859-1.
  • The bundle class is now an AbstractBundle and is final: the DependencyInjection\James2001OdtExtension and DependencyInjection\Configuration classes are gone. The james2001_odt.factory service and the Factory autowiring alias don't change.

Upgrading from 1.x

Apply these changes, then the ones of "Upgrading from 2.x" above:

  • The ODT classes now come from james2001/odtphp: \Odf becomes Odtphp\Odf and \Segment becomes Odtphp\Segment. The methods are the same.
  • setVars() expects UTF-8 by default (cybermonde/odtphp expected ISO-8859-1).
  • Factory::createOdtObject() and Factory::createSegment() have typed arguments and return types.
  • The sources moved to src/, and Resources/config/services.xml is gone: the service is declared by the extension. The service id james2001_odt.factory doesn't change.

Tests

composer install
vendor/bin/phpunit

License

This bundle is released under the MIT license (see LICENSE). The odtphp library it relies on is released under the GPL-3.0.