Would you like to have a Document Viewer embedded right into your Dynaforms? Part 1

By | March 3, 2011 | ProcessMaker

If so, read on…

Thanks to work from our partner Comunycarse Software Studios and some tweaking by me, now we can have a document’s contents displayed right into a Dynaform next to, above or below the Dynaform field’s like this:

Flashviewer screenshot 1

The Flash Viewer with a sample Adobe PDF document converted to SWF.

 

Integrating Open Source software/code from Ktplugins.com’s Wemag Online Document Viewer, SWFTOOLS‘ SWF Manipulation and Generation Utilities and Crirus’ Zviewer SWF Document Viewer and some JavaScript code, this is possible now.

Actually, this is done in two steps:

  1. Converting a document into a SWF file.
  2. Displaying the SWF file through an embedded Flash Viewer in the Dynaform.

All within ProcessMaker so that both procedures are totally transparent to the end user.

If you’re an intermediate to advanced ProcessMaker user and developer, you’ll find the following steps quite easy to implement.

We’re going to use CentOS 5.x server here as a host for ProcessMaker, but you can use any other Linux distro or Windows.

In Part 1 well cover:

Converting a document into a SWF file.

What we’re going to do here is convert a PDF file into a SWF file using SWFTOOLS pdf2swf utility for Linux. If you have other type of documents that you’d like to display within a Dynaform, you will need to find a tool to convert them to PDF format first. For example, we’re going to use here CentOS’ tiff2pdf tool to convert a TIFF file into a PDF file and then convert that PDF file into a SWF file for displaying in the Dynaform. All such conversions will be executed from within ProcessMaker itself using the PdfToSwfConverter.php class from the Wemag Online Document Viewer plugin.

Step1. Install SWFTOOLS utilities in CentOS:

Download SWFTOOLS latest version from http://www.swftools.org in source .tar.gz format.

Uncompress the downloaded .tar.gz file into a working directory using the following command:

tar zxvf swftools-0.9.1.tar.gz

Download and install the required packages in order to compile SWFTOOLS issuing the following command:

yum install zlib-devel libjpeg-devel giflib-devel freetype-devel gcc gcc-c++ make

Change to the directory where the SWFTOOLS file was uncompressed and compile and install by issuing the following commands:

./configure
make
make install

The tools will be copied to the /usr/local/bin directory. Now we need to create a symbolic link for the pdf2swf tool into the /usr/bin directory so that ProcessMaker can run this tool when needed, by issuing the following command:

ln -s /usr/local/bin/pdf2swf /usr/bin/pdf2swf

And now create the following directory structure: /opt/processmaker/workflow/public_html/files and assign the following permissions: chmod o+rw /opt/processmaker/workflow/public_html/files

Step 2. Installing the Wemag Online Document Viewer plugin.

Download the Wemag Online Document Viewer plugin from http://www.ktplugins.com/online-document-viewer

Uncompress the .zip file into a working directory, get into that directory and copy the /WemagOnlineDocumentViewer/PdfToSwfConverter.php file into the /opt/processmaker/workflow/engine/includes directory by issuing the following command: cp /WemagOnlineDocumentViewer/PdfToSwfConverter.php /opt/processmaker/workflow/engine/includes/PdfToSwfConverter.php

Now open the /opt/processmaker/workflow/engine/includes/PdfToSwfConverter.php file for editing with your favorite text editor and do the following modifications:

Find the function writeLog() and add this line:

$dest=PATH_UPLOAD;

Replace the block: if($logfile == null) with:

if($logfile == null) {
$logfile = $dest."wemag-online-documents.txt";
}

Find the function convertPdfToSwf() and change the $cmd= lines to:

for WIN remove the KT_DIR constant and in Linux change to:

$cmd = "pdf2swf "$src" -o "$destination"";

If the document to be converted is a TIFF file, we have to convert it to a PDF file first by adding the following lines into the Linux if block:

$ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
if($ext == "tif" || $ext == "tiff")
{
$cmd = "tiff2pdf "$src" -o "$destination".".pdf"";
PdfToSwfConverter::writeLog("Executing LIN command ".$cmd);
PdfToSwfConverter::writeLog("Command output: ");
PdfToSwfConverter::writeLog(exec($cmd));
$src = $destination . ".pdf";
}

Step 3. Doing the file conversion within ProcessMaker:

Now, if you want an uploaded Input Document in either PDF or TIFF format to be automatically converted by ProcessMaker into a SWF file, create the following trigger in ProcessMaker’s Process Editor and insert it to be run before the corresponding Input Document step:

$query="SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='".@@APPLICATION."'";
$docu=executeQuery($query);
$sAppDocUid=$docu[1]['APP_DOC_UID'];
@@flashFile="/files/".@@APPLICATION."/".$sAppDocUid.'_1.swf';
require_once("classes/model/AppDocumentPeer.php");
$oAppDocument = new AppDocument();
$oAppDocument->Fields = $oAppDocument->load($sAppDocUid,1);
$info = pathinfo($oAppDocument->getAppDocFilename());
$ext = $info['extension'];
$dest=PATH_UPLOAD.@@APPLICATION;
$folderPermission=0777;
if(!is_dir($dest)) {
@@exitodir = mkdir($dest,$folderPermission);
}
include_once("includes/PdfToSwfConverter.php");
if(!file_exists($dest."/".$sAppDocUid.'_1.swf')) {
@@exitoFile = PdfToSwfConverter::convertPdfToSwf(PATH_DOCUMENT.@@APPLICATION.'/'.$sAppDocUid.'_1.'.$ext, $dest."/".$sAppDocUid.'_1.swf');
}

The trigger will assign the converted SWF file’s path inside the /opt/processmaker/workflow/public_html/files/<APP_UID> directory to the @@flashFile variable, will create said path for physically storing the converted SWF file in there, will call the PdfToSwfConverter.php class to do the actual file conversion and will name the resulting SWF file using the uploaded Input Document’s UID and adding a _1 after that as well as the swf extension, so the resulting SWF file will be stored as /opt/processmaker/workflow/public_html/files/<APP_UID>/<APP_DOC_UID>_1.swf where APP_UID is the Case UID and APP_DOC_UID is the original uploaded Input Document file’s UID.

With this information, you can access the converted SWF file through a link in a Dynaform by using the @@flashFile variable’s stored value.

This finishes the file conversion and storage steps.

Tune in next week for the second part, where you will learn how to embed a Flash File Viewer into a Dynaform and how to load the converted SWF file into this viewer.

Los comentarios están cerrados.