PHP SwfTools documentation

PHP SwfTools


PHP SwfTools is a lib for manipulating PDF files and SWF files with SWFTools (


We rely on composer to use this library. If you do no still use composer for your project, you can start with this composer.json at the root of your project:

    "require": {
        "php-ffmpeg/php-ffmpeg": "master"

Install composer :

# Install composer
curl -s | php
# Upgrade your install
php composer.phar install

You now just have to autoload the library to use it :

require 'vendor/autoload.php';

This is a very short intro to composer. If you ever experience an issue or want to know more about composer, you will find help on their website

Basic Usage


API is quite simple : Two objects should be mainly used and cover the needs : FlashFile and PDFFile.


The following code extracts various data from a Swf file :


use SwfTools\FlashFile;
use SwfTools\Configuration;

$flash = new FlashFile('file.swf');

// Renders the flash file with swfrender

// List all embedded objects
// Available object types are one EmbeddedObject::TYPE_* constants
foreach($flash->listEmbeddedObjects() as $embeddedObject)
    $id = $embeddedObject->getId();

    // Extract an embedded object
    $flash->extractEmbedded($id, sprintf('output%d.jpg', $id));

// Extract the first image obecjt found (jpeg or png)


The following code converts a PDF to a Swf file :


use SwfTools\PDFFile;
use SwfTools\Configuration;

$pdf = new PDFFile('file.pdf');

Using Custom Configuration

PHP SwfTools autodetects SWFTools binaries on most *nix systems with the command where. If you would like to provide your own configuration, you can do it :


use SwfTools\PDFFile;
use SwfTools\Configuration;

$PDF = new PDFFile('file.pdf');
/* Will autodetect pdf2swf location */

$PDF = new PDFFile('file.pdf', new Configuration('pdf2swf'=>'/my/custom/path/to/pdf2swf'));
/* Will use /my/custom/path/to/pdf2swf */

Process Timeout

PHPSwfTools uses underlying processes to execute commands. You can set a timeout to prevent these processes to run more than a defined duration.

To disable timeout, set it to 0 (default value).

$configuration = new SwfTools\Configuration(array(
    'timeout' => 0

$file = new SwfTools\FlashFile('Animation.swf', $configuration);

Handling Exceptions

PHP-SwfTools throws 3 different types of exception :

  • \SwfTools\Exception\BinaryNotFoundException is thrown when no acceptable pdf2text binary is found.
  • \SwfTools\Exception\InvalidArgumentException is thrown when an invalid argument (file, format, ...) is provided
  • \SwfTools\Exception\RuntimeException which extends SPL RuntimeException

All these Exception implements \SwfTools\Exception\Exception so you can catch any of these exceptions by catching this exception interface.

Report a bug

If you experience an issue, please report it in our issue tracker. Before reporting an issue, please be sure that it is not already reported by browsing open issues.

When reporting, please give us information to reproduce it by giving your platform (Linux / MacOS / Windows) and its version, the version of PHP you use (the output of php --version), the version of swftools you use (the output of swfextract --version).

Ask for a feature

We would be glad you ask for a feature ! Feel free to add a feature request in the issues manager on GitHub !


You find a bug and resolved it ? You added a feature and want to share ? You found a typo in this doc and fixed it ? Feel free to send a Pull Request on GitHub, we will be glad to merge your code.

Run tests

PHP-SwfTools relies on PHPUnit for unit tests. To run tests on your system, ensure you have PHPUnit installed, and, at the root of PHP-SwfTools, execute it :



PHP-SwfTools has been written by Romain Neutron @ Alchemy for Phraseanet, our DAM software. Try it, it’s awesome !


PHP-SwfTools is licensed under the MIT License