Convert PDF documents to HTML5, Adobe Flash or HTML4 with PHP

FlowPaper 1.4.5 and later provides sample scripts in PHP for on the fly conversion and publishing of PDF documents using the suggested PDF to flash toolkit SWFTools.

Make sure you have the following installed:

To install FlowPaper, simply extract the contents of the FlowPaper distribution zip file to one of your web server's folders.

Preparation - installing the prerequisites

FlowPaper can use a few different open source libraries to optimize the display of documents. Links to these libraries are available on our download page. The following example shows how to install these components on a Ubuntu system. Run these commands as root.

apt-get install pdftk
apt-get install mupdf-tools
mkdir pdf2json
cd pdf2json
tar -zxvf pdf2json-0.68.tar.gz
make && make install

Step 1 - Configuring using the guide - starting the set up

Our PHP package comes with a guide which helps you check that the required tools are installed and that your server is correctly configured.

To start this guide after extracting the contents of our zip file to your web server, navigate your browser to "/php/setup.php".

The screen to the right should be visible when opening the setup.php page in your browser. It outlines the basic requirements that needs to be met for FlowPaper to be able to work on your server.

As you can see in the screen shot, one of the conditions are not met on our server. The configuration file that FlowPaper uses needs to be writeable so that FlowPaper can save its configuration. We therefore execute the following command on our server:

cd /var/www/php_demo/php/config/
sudo chmod 777 config.ini.nix.php
The page will clear to green once you refresh it in your browser.

Step 2 - Configuring using the guide - verifying required server components

The next step in the guide verifies that all required third party open source components are installed on the server. You can see to the right that all components are installed on the server this guide was documented on. How to install these components will depend a little on what system you are configuring (Linux or Windows). Please use the links at the top of this page to access the individual components.

You can also see that our server has a limitation in upload size. This is nothing to worry about if your documents are smaller than 10 megabyte in size but if you want to change this setting then please edit your php.ini file and adjust this setting.

Step 3 - Configuring using the guide - directory and log in settings

This final step will let you assign a username and password for your installation. It will also ask you where you would like your PDF documents to be stored as well as where you would like to use as a working directory for FlowPaper. FlowPaper needs this directory to be able to read converted files. We have choosen to use the directory '/var/www/php_demo/php/pdf/'.

You can see in the screen shot to the right that we are getting an error in our installation saying that the set up cannot write to the directory we have specified. We therefore execute the following command on our Linux server:

cd /var/www/php_demo/php/
sudo chmod 777 -R pdf
Clicking on 'retry' will clear the error message. Repeat the same step for your working directory if needed.

You can als choose what viewing technology you would like to use as primary and secondary for the viewer (commercial viewer only).

Step 4 - Configuring using the guide - uploading and viewing documents

You should be presented with a empty listing of documents now that you are finished configuring your environment. Clicking on the 'UPLOAD' button will allow you to upload a document to your server.

We have uploaded a document called 'Paper.pdf' to our server in our example. Clicking on this document will open the document in your browser.

You can use the URL that has opened in the browser (with the 'split_document.php' file name in its path) and link to this document from places on your own web site if you wish.

Manual configuration

FlowPaper comes with a configuration sample file for Windows and Linux based systems. These configuration files are automatically populated for you if you are using the guide but you can also choose to edit these files manually. The configuration files are located in the "php/config/" directory and are named "config.ini.nix.php" for Linux based systems and "" for Windows systems.
The following code snippet is taken from the Windows configuration file.

 path.pdf = 'C:\inetpub\wwwroot\flowpaper\php\pdf\'
 path.swf = 'C:\inetpub\wwwroot\flowpaper\php\docs\'

[external commands]
 cmd.conversion.singledoc = '"C:\Program Files\SWFTools\pdf2swf.exe" {path.pdf}{pdffile} -o {path.swf}{pdffile}.swf -f -T 9 -t -s storeallcharacters'
 cmd.conversion.splitpages = '"C:\Program Files\SWFTools\pdf2swf.exe" {path.pdf}{pdffile} -o {path.swf}{pdffile}%.swf -f -T 9 -t -s storeallcharacters'
 cmd.searching.extracttext = '"C:\Program Files\SWFTools\swfstrings.exe" {path.swf}{swffile}'

Make sure that path.pdf points to a directory where you have the PDF files you want to publish and that path.swf points to a directory where you want to store your published documents. Also make sure that the path to SWFTools is correctly pointing to where you have it installed.


For the publishing to work, the path.swf directory needs to have write permissions for the web user. On Windows based systems, this can be done by letting the executing account has write permissions to the folder (or by letting the "Users" group has write permission to the folder). Linux users accomplish the same setting by executing chmod 777 on this folder.

These directories do not need to reside inside the web root and a good idea is to place them somewhere else if you want to stay in control of how your documents are read.

All done!
You should now be able to run the PHP sample scripts included in the FlowPaper distribution zip file. All sample files can be accessed through "index.html".