]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 24 Jan 2014 14:39:24 +0000 (14:39 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 24 Jan 2014 14:39:24 +0000 (14:39 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/Metier/class.ws.document.php

index bbcac4f28c550c7bfa07050f094a741cd3ce60c1..801a72dbde7a245facec80474e16d3956b48c5f5 100644 (file)
@@ -829,12 +829,9 @@ class wsMaintenance {
                } else {
                        return;
                }
-
                if (!$value) {
                        return;
                }
-
-
                $newlinks = array();
                foreach ($links as $link) {
                        $link[$k]+=$value;
@@ -845,6 +842,31 @@ class wsMaintenance {
                $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Offset links positions (' . $direction . ' :: ' . $value . ')', $core->user->utilisateur_id);
        }
 
-}
+       public function extractTexts($args) {
+               global $core;
+               $book_id = $args[0];
+               $dao = new wsDAOBook($core->con);
+               $book = $dao->selectById($book_id);
+               $pages = $dao->getPagesOfBook($book_id);
 
-?>
\ No newline at end of file
+               $docs = array();
+               foreach ($pages as $p) {
+                       $docs[] = $p['document_id'];
+               }
+               $docs = array_unique($docs);
+
+               foreach ($docs as $doc) {
+                       $out = WS_DOCS . '/' . $doc . '/';
+
+                       $fwstk = new cubeCommandLine('fwstk');
+                       $fwstk->setPath(CONVERTER_PATH);
+                       $fwstk->setArg('--input ' . $out . '/crop.pdf');
+                       $fwstk->setArg('--extractTexts ' . $out . '%s%d.txt');
+                       if ($book->parametres->ignoreSearchSeparators != '') {
+                               $fwstk->setArg('--ignoreSeparators ' . $book->parametres->ignoreSearchSeparators);
+                       }
+                       $fwstk->execute();
+               }
+       }
+
+}
index 5cd60abcfa7f4964ccbecc00458a0891759dc170..0c8549e760e331e6a5f83eaa6420a44f292d4285 100644 (file)
@@ -855,7 +855,6 @@ class wsDAOBook extends commonDAO {
                }
                ksort($index);
 
-
                $textes = json_encode($textes);
                $index = json_encode($index);
 
index 044e0cd805b9363c67ef0550fb761471be78b210..3bdd425e7784520f934127d5ed3e5ad5c5593b3a 100644 (file)
-<?php\r
-\r
-/**\r
- * wsDocument\r
- *\r
- * @package\r
- * @author Vincent\r
- * @copyright Copyright (c) 2010\r
- * @version $Id$\r
- * @access public\r
- */\r
-class wsDocument extends cubeMetier {\r
-\r
-       protected $document_id;\r
-       protected $file;\r
-       protected $proprietaire;\r
-       protected $pages;\r
-       protected $trim;\r
-       protected $date;\r
-       protected $localInfos;\r
-       protected $generalInfos;\r
-       protected $conversionInfos;\r
-       protected $bookmarks;\r
-       protected $numberSections;\r
-       protected $localHash;\r
-       protected $version;\r
-       // Crop & cut\r
-       protected $autocrop;\r
-       protected $manualcrop;\r
-       protected $autocut;\r
-       protected $manualcut;\r
-       // Files\r
-       protected $out;\r
-       protected $in;\r
-       protected $html;\r
-       protected $uncompressed;\r
-       protected $log;\r
-       protected $common_log_pointer;\r
-       protected $pages_log_pointers;\r
-       protected $infos;\r
-       protected $cropped;\r
-       protected $rgb;\r
-\r
-       const NORMAL = 0;\r
-       const FLATTEN = 1;\r
-       const POLY2BITMAP = 2;\r
-       const BITMAP = 3;\r
-       const BARBARE_PNM = 4;\r
-       const BARBARE_GS = 5;\r
-       const MAX = 5;\r
-       const PNM_FILL = 2;\r
-\r
-       protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
-       // Number section styles\r
-       protected static\r
-                       $numberStyles = array('NoNumber' => 'no', 'DecimalArabicNumerals' => 'decimal',\r
-               'UppercaseRomanNumerals' => 'roman_up', 'LowercaseRomanNumerals' => 'roman_low',\r
-               'UppercaseLetters' => 'letters_up', 'LowercaseLetters' => 'letters_low');\r
-\r
-       public function init() {\r
-               $this->out = WS_DOCS . '/' . $this->document_id . '/';\r
-               $this->log = $this->out . '/logs/';\r
-               $this->html = $this->out . '/html/';\r
-               $this->in = $this->out . 'original.pdf';\r
-               $this->uncompressed = $this->out . 'uncompressed.pdf';\r
-               $this->infos = $this->out . 'infos.txt';\r
-               if (!file_exists($this->out)) {\r
-                       mkdir($this->out, 0755, true);\r
-                       mkdir($this->log, 0755);\r
-               }\r
-               if (!file_exists($this->html)) {\r
-                       mkdir($this->html, 0755);\r
-               }\r
-               $this->cropped = $this->out . 'crop.pdf';\r
-               $this->pages_log_pointers = array();\r
-\r
-               if (is_null($this->conversionInfos)) {\r
-                       $this->conversionInfos = new wsDocumentConversionInfos();\r
-               }\r
-       }\r
-\r
-       public function copyOriginalFromUpload($tmp_file) {\r
-               move_uploaded_file($tmp_file, $this->in);\r
-       }\r
-\r
-       public function copyOriginalFromOlderVersion() {\r
-               if (!file_exists($this->in)) {\r
-                       copy('http://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);\r
-               }\r
-       }\r
-\r
-       public function extractFonts() {\r
-               $extractor = new wsPDFFontExtractor($this->out, $this);\r
-               $extractor->extract();\r
-       }\r
-\r
-       public function getInfos($in = null, $force = false) {\r
-               if (is_null($in)) {\r
-                       $in = $this->in;\r
-               }\r
-\r
-               $fwstk = new cubeCommandLine('fwstk');\r
-               $fwstk->setPath(CONVERTER_PATH);\r
-               $fwstk->setArg('--input ' . $in);\r
-               $fwstk->setArg('--infos');\r
-               $fwstk->execute();\r
-               $this->addToLog($fwstk);\r
-               $out = $fwstk->output;\r
-\r
-               $pdfinfo = new cubeCommandLine('pdfinfo');\r
-               $pdfinfo->setPath(CONVERTER_PATH);\r
-               $pdfinfo->setArg('-box');\r
-               $pdfinfo->setArg('f', 1);\r
-               $pdfinfo->setArg('l', 100000);\r
-               $pdfinfo->setArg(null, $in);\r
-               $pdfinfo->execute();\r
-               $this->addToLog($pdfinfo);\r
-               $out.="\n";\r
-               $out.=$pdfinfo->output;\r
-\r
-               $this->parseInfos($out);\r
-\r
-               $this->conversionInfos->setPageNumber($this->generalInfos['pages']);\r
-\r
-               file_put_contents($this->infos, $out);\r
-               $this->findCutDisposition();\r
-       }\r
-\r
-       public function findCutDisposition() {\r
-               $this->detectSpreads();\r
-               $this->detectPageDifferences();\r
-       }\r
-\r
-       protected function detectPageDifferences() {\r
-               // Vérifie si la cropbox et la trimbox sont identiques pour toutes les pages\r
-               $difference = false;\r
-               foreach ($this->generalInfos['page'] as $page => $infos) {\r
-                       if (!isset($infos['crop']) || !isset($infos['crop'])) {\r
-                               continue;\r
-                       }\r
-                       if ($infos['crop'] != $infos['trim']) {\r
-                               $difference = true;\r
-                       }\r
-               }\r
-               if (!$difference) {\r
-                       return false;\r
-               }\r
-               // Vérifie si la trimbox définie toutes les pages de la même taille\r
-               $heights = array();\r
-               $widths = array();\r
-               foreach ($this->generalInfos['page'] as $page => $infos) {\r
-                       $heights[] = round($infos['trim']->height);\r
-                       $widths[] = round($infos['trim']->width);\r
-               }\r
-               $heights = array_unique($heights);\r
-               $widths = array_unique($widths);\r
-               if (count($heights) == 1 && count($widths) == 1) {\r
-                       $this->autocrop = 'trim';\r
-                       $this->manualcrop = false;\r
-               } else {\r
-                       $this->autocrop = false;\r
-                       $this->manualcrop = true;\r
-               }\r
-       }\r
-\r
-       protected function detectSpreads() {\r
-               // Détection des spreads\r
-\r
-               $this->autocut = false;\r
-               $this->manualcut = false;\r
-               if ($this->generalInfos['pages'] <= 2) {\r
-                       return;\r
-               }\r
-\r
-               foreach ($this->generalInfos['page'] as $page => $infos) {\r
-                       if ($page == 1) {\r
-                               $first = $infos['size'];\r
-                       } elseif ($page == $this->generalInfos['pages']) {\r
-                               $last = $infos['size'];\r
-                       } elseif ($page == 2) {\r
-                               $second = $infos['size'];\r
-                       }\r
-               }\r
-\r
-               if ($first == $last && $last == $second) {\r
-                       $ratio = $first[0] / $first[1];\r
-                       $this->autocut = false;\r
-                       if ($ratio <= 1) {\r
-                               $this->manualcut = false;\r
-                       } elseif ($ratio >= 6) {\r
-                               $this->manualcut = 'L8';\r
-                       } elseif ($ratio >= 3) {\r
-                               $this->manualcut = 'L4';\r
-                       } elseif ($ratio >= 2) {\r
-                               $this->manualcut = 'L3';\r
-                       } else {\r
-                               $this->manualcut = '14-23';\r
-                       }\r
-                       return;\r
-               }\r
-               $this->manualcut = false;\r
-               if (self::compareSizes($last, $first) && cubeMath::compare($first[0] * 2, $second[0], 0.9)) {\r
-                       $this->autocut = '1-23-4';\r
-               }\r
-               if (cubeMath::compare($first[0] * 2, $second[0], 0.9) && self::compareSizes($last, $second)) {\r
-                       $this->autocut = '1-23';\r
-               }\r
-\r
-               $this->addToLog('Detect Spreads : Manual cut ' . $this->manualcut . ' ; Auto cut : ' . $this->autocut);\r
-       }\r
-\r
-       public static function compareSizes($x, $y, $tolerance = 0.9) {\r
-               return cubeMath::compare($x[0], $y[0], $tolerance) && cubeMath::compare($x[1], $y[1], $tolerance);\r
-       }\r
-\r
-       public function parseInfos($data) {\r
-               // This function get general infos (pages sizes, boxes, number sections and\r
-               // bookmarks\r
-               // Init arrays\r
-               $this->generalInfos = array();\r
-               $this->generalInfos['size'] = array(0, 0);\r
-               $this->bookmarks = array();\r
-               $this->numberSections = '';\r
-               $bookmark_id = 0;\r
-\r
-               $res['size'] = array(0, 0);\r
-               $lines = explode("\n", $data);\r
-               foreach ($lines as $line) {\r
-                       $line = trim(cubeText::condenseWhite($line));\r
-                       $e = explode(':', $line, 2);\r
-                       $k = trim($e[0]);\r
-                       if (count($e) < 2) {\r
-                               continue;\r
-                       }\r
-                       $v = trim($e[1]);\r
-                       if ($k == 'Pages' || $k == 'NumberOfPages') {\r
-                               $this->pages = $this->generalInfos['pages'] = $v;\r
-                               $this->generalInfos['page'] = array();\r
-                               for ($i = 1; $i <= $this->pages; $i++) {\r
-                                       $this->generalInfos['page'][$i] = array();\r
-                               }\r
-                       } elseif (preg_match('|Page\s+([0-9]+)\s+(.*)Box:\s+([0-9.]*)\s+([0-9.]*)\s+([0-9.]*)\s+([0-9.]*)|iu', $line, $m)) {\r
-                               $this->generalInfos['page'][$m[1]][strtolower($m[2])] = new wsBox($m[3], $m[4], $m[5], $m[6]);\r
-                       } elseif (preg_match('|Page\s+([0-9]+)\s+size:\s+([0-9.]*)[pts[:space:]]+x\s+([0-9.]*)\s+pts|iu', $line, $m)) {\r
-                               $this->generalInfos['page'][$m[1]]['size'] = array($m[2], $m[3]);\r
-                               if ($m[1] == 1) {\r
-                                       $this->generalInfos['size'][0] = $m[2];\r
-                                       $this->generalInfos['size'][1] = $m[3];\r
-                               }\r
-                       } elseif ($k == 'BookmarkTitle') {\r
-                               $this->bookmarks[$bookmark_id] = array('titre' => str_replace('&#13;', '', trim($v)));\r
-                       } elseif ($k == 'BookmarkLevel') {\r
-                               $this->bookmarks[$bookmark_id]['level'] = $v;\r
-                       } elseif ($k == 'BookmarkPageNumber') {\r
-                               $this->bookmarks[$bookmark_id]['page'] = $v;\r
-                               $bookmark_id++;\r
-                       } elseif ($k == 'NumberSections') {\r
-                               $this->numberSections = $v;\r
-                       }\r
-               }\r
-\r
-               return $res;\r
-       }\r
-\r
-       public function getPagesNumber() {\r
-               $this->getInfos();\r
-               return $this->generalInfos['pages'];\r
-       }\r
-\r
-       public function globalOperations() {\r
-               $this->getInfos();\r
-               if ($this->CropAndCut()) {\r
-                       $this->getInfos($this->cropped, true);\r
-               }\r
-               $this->getLinksAndTexts();\r
-       }\r
-\r
-       public function CropAndCut() {\r
-               if (!$this->isCropped()) {\r
-                       copy($this->in, $this->cropped);\r
-                       return false;\r
-               }\r
-               if ($this->autocrop == 'trim') {\r
-                       $this->trimDocument();\r
-               } else {\r
-                       copy($this->in, $this->cropped);\r
-               }\r
-\r
-               if ($this->autocut) {\r
-                       $this->cutDocument($this->autocut);\r
-                       return true;\r
-               }\r
-               return false;\r
-       }\r
-\r
-       public function cutDocument($mode) {\r
-               $fwstk = new cubeCommandLine('fwstk');\r
-               $fwstk->setPath(CONVERTER_PATH);\r
-               $fwstk->setArg('--input ' . $this->in);\r
-               $fwstk->setArg('--cut ' . $mode);\r
-               $fwstk->setArg('--output ' . $this->cropped);\r
-               $fwstk->execute();\r
-               $this->addToLog($fwstk);\r
-       }\r
-\r
-       public function trimDocument() {\r
-               $fwstk = new cubeCommandLine('fwstk');\r
-               $fwstk->setPath(CONVERTER_PATH);\r
-               $fwstk->setArg('--input ' . $this->in);\r
-               $fwstk->setArg('--trim');\r
-               $fwstk->setArg('--output ' . $this->cropped);\r
-               $fwstk->execute();\r
-               $this->addToLog($fwstk);\r
-       }\r
-\r
-       public function processOnePage($page, $force = true) {\r
-               if ($force) {\r
-                       $this->addToLog('Processing page #' . $page);\r
-                       $this->makeMiniShot($page);\r
-                       $this->makeSWFFiles($page);\r
-                       $this->makeHTML5Files($page);\r
-               }\r
-       }\r
-\r
-       public function processAllPages() {\r
-               for ($i = 1; $i <= $this->generalInfos['pages']; $i++) {\r
-                       $this->processOnePage($i);\r
-               }\r
-               $this->optimizeSVG();\r
-       }\r
-\r
-       public function optimizeSVG() {\r
-\r
-\r
-\r
-               $scour = new cubeCommandLine('scour.php');\r
-               $scour->setPath(CONVERTER_PATH);\r
-               $scour->setNohup(true);\r
-               $scour->setArg(null, $this->html);\r
-               $scour->execute();\r
-       }\r
-\r
-       public function processRange($pages) {\r
-               foreach ($pages as $i) {\r
-                       $this->processOnePage($i);\r
-               }\r
-               $this->optimizeSVG();\r
-       }\r
-\r
-       public function getLinksAndTexts() {\r
-               $fwstk = new cubeCommandLine('fwstk');\r
-               $fwstk->setPath(CONVERTER_PATH);\r
-               $fwstk->setArg('--input ' . $this->cropped);\r
-               $fwstk->setArg('--extractTexts ' . $this->out . '%s%d.txt');\r
-               $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');\r
-               $fwstk->execute();\r
-               $this->addToLog($fwstk);\r
-\r
-               /* $fwstk = new cubeCommandLine('fwstk');\r
-                 $fwstk->setPath(CONVERTER_PATH);\r
-                 $fwstk->setArg('--input ' . $this->cropped);\r
-                 $fwstk->setArg('--layout ' . $this->html . 'p%d.layout');\r
-                 $fwstk->setArg('--cmaps ' . $this->html);\r
-                 $fwstk->setArg('--fonts' . $this->out . 'fonts/web/');\r
-                 $fwstk->execute();\r
-                 $this->addToLog($fwstk); */\r
-       }\r
-\r
-       public function makeMiniShot($page) {\r
-               $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'PNM');\r
-       }\r
-\r
-       public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') {\r
-               // Make thumbs of $w width\r
-               // resolution 72 make 1pt=1px\r
-               $width = $this->generalInfos['size'][0];\r
-               $ratio = $width / $w;\r
-               $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);\r
-       }\r
-\r
-       public function makeShotFixedHeight($page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM') {\r
-               // Make thumbs of $w height\r
-               // resolution 72 make 1pt=1px\r
-               $height = $this->generalInfos['size'][1];\r
-               $ratio = $height / $h;\r
-               $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);\r
-       }\r
-\r
-       public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null) {\r
-               $error = false;\r
-               if (is_null($in)) {\r
-                       $in = $this->cropped;\r
-               }\r
-               // Delete all old files\r
-               $res = $this->out . $prefix . $page . '.jpg';\r
-               if (file_exists($res)) {\r
-                       @unlink($res);\r
-               }\r
-\r
-               if ($method == 'GS') {\r
-                       $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
-               } elseif ($method == 'PNM') {\r
-                       $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
-               }\r
-               // Test the result by checking all files\r
-               if (!file_exists($res)) {\r
-                       $error = true;\r
-               }\r
-               // If error, we try to make thumbs with other method\r
-               if ($error) {\r
-                       if ($method == 'GS') {\r
-                               $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
-                       } elseif ($method == 'PNM') {\r
-                               $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
-                       }\r
-               }\r
-       }\r
-\r
-       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null) {\r
-               if (is_null($in)) {\r
-                       $in = $this->cropped;\r
-               }\r
-               // Fabrication des thumbanails avec ghostscript\r
-               $gs = new cubeCommandLine('gs', null, true);\r
-               $gs->setPath(CONVERTER_PATH);\r
-               $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
-               $gs->setArg('-dBATCH');\r
-               $gs->setArg('-dNOPAUSE');\r
-               $gs->setArg('-dNOPROMPT');\r
-               // Antialias\r
-               $gs->setArg('-dDOINTERPOLATE');\r
-               $gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
-               $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
-               // Device\r
-               $gs->setArg('-sDEVICE=jpeg');\r
-               // Dispotion & colors\r
-               // $gs->setArg('-dUseCIEColor');\r
-               $gs->setArg('-dAutoRotatePages=/None');\r
-               $gs->setArg('-dUseCropBox');\r
-               // Resolution & Quality\r
-               $gs->setArg('-r' . round($resolution));\r
-               $gs->setArg('-dJPEGQ=' . $quality);\r
-               // Performances\r
-               $gs->setArg('-dNumRenderingThreads=4');\r
-               // Page range\r
-               $gs->setArg('-dFirstPage=' . $page);\r
-               $gs->setArg('-dLastPage=' . $page);\r
-               // Files\r
-               $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . $page . '.jpg');\r
-\r
-               $gs->setArg(null, $in);\r
-               $gs->execute();\r
-               $this->addToLog($gs, true, $page);\r
-       }\r
-\r
-       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true) {\r
-               if (is_null($in)) {\r
-                       $in = $this->cropped;\r
-               }\r
-\r
-               $tmp = cubeFiles::tempnam();\r
-\r
-               $antialiasing = $antialiasing ? 'yes' : 'no';\r
-               $freetype = $texts ? 'yes' : 'no';\r
-               $resolution = $resolution;\r
-               // Exporte les fichiers\r
-               $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
-               $pdftoppm->setPath(CONVERTER_PATH);\r
-\r
-               $pdftoppm->setArg('f', $page);\r
-               $pdftoppm->setArg('l', $page);\r
-               $pdftoppm->setArg('-cropbox');\r
-               $pdftoppm->setArg('-freetype ' . $freetype);\r
-               $pdftoppm->setArg('-singlefile');\r
-               $pdftoppm->setArg('-aa ' . $antialiasing);\r
-               $pdftoppm->setArg('-aaVector ' . $antialiasing);\r
-               $pdftoppm->setArg('r', $resolution);\r
-               $pdftoppm->setArg(null, $in);\r
-               $pdftoppm->setArg(null, $tmp);\r
-               $pdftoppm->execute();\r
-               $this->addToLog($pdftoppm, true, $page);\r
-\r
-               $tmp.='.ppm';\r
-\r
-               $jpegfile = $this->out . $prefix . $page . '.jpg';\r
-\r
-\r
-               if (file_exists($tmp)) {\r
-                       $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false);\r
-                       $pnmtojpeg->setArg('-quality ' . $quality);\r
-                       $pnmtojpeg->setArg(null, $tmp);\r
-                       $pnmtojpeg->execute();\r
-                       $this->addToLog($pnmtojpeg, false, $page);\r
-\r
-                       unlink($tmp);\r
-               }\r
-       }\r
-\r
-       protected function isCropped() {\r
-               return $this->autocrop || $this->manualcrop || $this->autocut || $this->manualcut;\r
-       }\r
-\r
-       public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version = null) {\r
-               $conversionSettings = $this->conversionInfos->pages[$page];\r
-               if (is_null($storeAllChars)) {\r
-                       $storeAllChars = true;\r
-               }\r
-               if (is_null($resolution)) {\r
-                       $resolution = $conversionSettings->resolution;\r
-               }\r
-               if (is_null($method)) {\r
-                       $method = $conversionSettings->method;\r
-               }\r
-               if (is_null($quality)) {\r
-                       $quality = $conversionSettings->quality;\r
-               }\r
-               if (is_null($maxObjects)) {\r
-                       $maxObjects = $conversionSettings->objects;\r
-               }\r
-               if (is_null($version)) {\r
-                       $version = isset($conversionSettings->version) ? $conversionSettings->version : 'stable';\r
-               }\r
-\r
-               if ($maxObjects <= 1) {\r
-                       $method = self::POLY2BITMAP;\r
-               }\r
-\r
-               // Pour les fichiers croppés, on utilise la méthode flatten qui ne prends\r
-               // pas en compte les objets hors de la box\r
-               if ($this->isCropped()) {\r
-                       // $method = max($method, self::FLATTEN);\r
-               }\r
-\r
-               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, 'p', $version);\r
-               if ($method < self::BARBARE_PNM) {\r
-                       // Analyse de la sortie pour détecter des typos manquantes\r
-                       $overflow = false;\r
-                       $overflowObjects = false;\r
-                       $written = false;\r
-                       $missing_fonts = array();\r
-                       if (file_exists($out)) {\r
-                               $fp = fopen($out, 'rb');\r
-                               while ($line = fgets($fp)) {\r
-                                       if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) {\r
-                                               $missing_fonts[] = $matches[1];\r
-                                       } elseif (stristr($line, 'ID Table overflow')) {\r
-                                               $overflow = true;\r
-                                       } elseif (stristr($line, 'NOTICE  SWF written')) {\r
-                                               $written = true;\r
-                                       } elseif (stristr($line, 'NOTICE  Writing SWF file')) {\r
-                                               $written = true;\r
-                                       }\r
-                               }\r
-                       }\r
-                       if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {\r
-                               $written = true;\r
-                       }\r
-                       // On teste si le fichier est écrit et qu'il a été généré par le premier niveau\r
-                       if ($method < self::POLY2BITMAP && $written) {\r
-                               $overflowObjects = $this->checkObjectsNumber($this->out . 'p' . $page . '.swf', $maxObjects, $page);\r
-                       }\r
-\r
-                       if (!$written || $overflow || $overflowObjects) {\r
-                               if ($method == self::MAX) {\r
-                                       return;\r
-                               }\r
-                               $nextMethod = $method + 1;\r
-                               return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $nextMethod, $version);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public function makeHTML5Files($page) {\r
-               // Then make HD background shots\r
-               $resolutions = array(300 => 85, 150 => 85, 36 => 85);\r
-               foreach ($resolutions as $r => $q) {\r
-                       $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false);\r
-                       $this->makeShotPNM($page, 'html/t' . $r . '-', $r, $q, 4, null, true);\r
-               }\r
-               $this->makeSVGFile($page);\r
-       }\r
-\r
-       public function makeSVGFile($page) {\r
-               $svgFile = $this->out . '/html/p' . $page . '.svg';\r
-               $svgOpt = $this->out . '/html/o' . $page . '.svg';\r
-\r
-               $pdftocairo = new cubeCommandLine('pdftocairo');\r
-               $pdftocairo->setPath(CONVERTER_PATH);\r
-               $pdftocairo->setArg('f', $page);\r
-               $pdftocairo->setArg('l', $page);\r
-               $pdftocairo->setArg(null, '-svg');\r
-               $pdftocairo->setArg(null, '-cropbox');\r
-               $pdftocairo->setArg(null, $this->cropped);\r
-               $pdftocairo->setArg(null, $svgFile);\r
-               $pdftocairo->execute();\r
-               $this->addToLog($pdftocairo, true, $page);\r
-\r
-               $this->_cleanSVG($svgFile);\r
-       }\r
-\r
-       protected function _cleanSVG($svgFile) {\r
-               $svg = new DOMDocument();\r
-               $svg->preserveWhiteSpace = false;\r
-               $svg->load($svgFile);\r
-\r
-               // Operations to delete \r
-               $xpath = new DOMXPath($svg);\r
-               $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');\r
-               $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');\r
-               $xpath->registerNamespace("php", "http://php.net/xpath");\r
-               $xpath->registerPhpFunctions('has_not_text');\r
-               $toDelete = array('//svg:defs/svg:clipPath',\r
-                       '//svg:defs/svg:image',\r
-                       '//svg:defs/svg:pattern',\r
-                       '/svg:svg/svg:g/svg:g[not(svg:use[@xlink:href])]',\r
-                       '/svg:svg/svg:g/svg:path',\r
-                       '/svg:svg/svg:g/svg:rect',\r
-               );\r
-\r
-               global $svglog;\r
-               $svglog = array('XPATH : ' . print_r($xpath, true));\r
-               foreach ($toDelete as $q) {\r
-                       $list = $xpath->query($q);\r
-                       $svglog[] = "Evaluate xpath query " . $q;\r
-                       $svglog[] = 'Give ' . $list->length . ' results';\r
-                       $svglog[] = 'Deleting Nodes in ' . print_r($list, true);\r
-                       if (count($list)) {\r
-                               foreach ($list as $node) {\r
-\r
-                                       /* @var $node DOMNode */\r
-                                       $parent = $node->parentNode;\r
-                                       $parent->removeChild($node);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               $this->addToLog(implode("\n", $svglog), false, $page);\r
-               file_put_contents($svgFile, $svg->saveXML());\r
-       }\r
-\r
-       protected function checkObjectsNumber($file, $maxObjects, $page) {\r
-               $swfdump = new cubeCommandLine('swfdump', null, true);\r
-               $swfdump->setPath(CONVERTER_PATH);\r
-               $swfdump->setArg(null, $file);\r
-               $swfdump->execute();\r
-               $this->addToLog($swfdump, true, $page);\r
-\r
-               str_replace('[01a]', '', $swfdump->output, $nbObjects);\r
-               if ($nbObjects > $maxObjects) {\r
-                       return true;\r
-               }\r
-               return false;\r
-       }\r
-\r
-       protected function dumpSWF($page, $prefix = 'p') {\r
-               $swfdump = new cubeCommandLine('/usr/local/swftools/special-swfdump/bin/swfdump', null, true);\r
-               $swfdump->setPath(CONVERTER_PATH);\r
-               $swfdump->setArg('t');\r
-               $swfdump->setArg('p');\r
-               $swfdump->setArg('F');\r
-               $swfdump->setArg(null, $this->out . $prefix . $page . '.swf');\r
-               $swfdump->execute();\r
-               $this->addToLog($swfdump, false, $page);\r
-               return $swfdump->output;\r
-       }\r
-\r
-       /**\r
-        * wsDocument::pdf2swf()\r
-        *\r
-        * @param mixed $page\r
-        * @param integer $resolution\r
-        * @param integer $quality\r
-        * @param mixed $storeAllChars\r
-        * @param integer $method\r
-        * @return\r
-        */\r
-       protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version = 'stable') {\r
-               /*\r
-                 -h , --help                    Print short help message and exit\r
-                 -V , --version                 Print version info and exit\r
-                 -o , --output file.swf         Direct output to file.swf. If file.swf contains '%' (file%.swf), then each page goes to a seperate file.\r
-                 -p , --pages range             Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or\r
-                 -P , --password password       Use password for deciphering the pdf.\r
-                 -v , --verbose                 Be verbose. Use more than one -v for greater effect.\r
-                 -z , --zlib                    Use Flash 6 (MX) zlib compression.\r
-                 -i , --ignore                  Allows pdf2swf to change the draw order of the pdf. This may make the generated\r
-                 -j , --jpegquality quality     Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)\r
-                 -s , --set param=value         Set a SWF encoder specific parameter.  See pdf2swf -s help for more information.\r
-                 -w , --samewindow              When converting pdf hyperlinks, don't make the links open a new window.\r
-                 -t , --stop                    Insert a stop() command in each page.\r
-                 -T , --flashversion num        Set Flash Version in the SWF header to num.\r
-                 -F , --fontdir directory       Add directory to the font search path.\r
-                 -b , --defaultviewer           Link a standard viewer to the swf file.\r
-                 -l , --defaultloader           Link a standard preloader to the swf file which will be displayed while the main swf is loading.\r
-                 -B , --viewer filename         Link viewer filename to the swf file.\r
-                 -L , --preloader filename      Link preloader filename to the swf file.\r
-                 -q , --quiet                   Suppress normal messages.  Use -qq to suppress warnings, also.\r
-                 -S , --shapes                  Don't use SWF Fonts, but store everything as shape.\r
-                 -f , --fonts                   Store full fonts in SWF. (Don't reduce to used characters).\r
-                 -G , --flatten                 Remove as many clip layers from file as possible.\r
-                 -I , --info                    Don't do actual conversion, just display a list of all pages in the PDF.\r
-                 -Q , --maxtime n               Abort conversion after n seconds. Only availableon Unix.\r
-\r
-                 PDF device global parameters:\r
-                 -----------------------------\r
-                 fontdir=<dir>     a directory with additional fonts\r
-                 font=<filename>   an additional font filename\r
-                 pages=<range>     the range of pages to convert (example: pages=1-100,210-)\r
-                 zoom=<dpi>        the resultion (default: 72)\r
-                 languagedir=<dir> Add an xpdf language directory\r
-                 multiply=<times>  Render everything at <times> the resolution\r
-                 poly2bitmap       Convert graphics to bitmaps\r
-                 bitmap            Convert everything to bitmaps\r
-\r
-                 SWF Parameters :\r
-                 ----------------\r
-                 SWF layer options :\r
-                 -------------------\r
-\r
-                 jpegsubpixels=<pixels>      resolution adjustment for jpeg images (same as jpegdpi, but in pixels)\r
-                 ppmsubpixels=<pixels        resolution adjustment for  lossless images (same asppmdpi, but in pixels)\r
-                 subpixels=<pixels>          shortcut for setting both jpegsubpixels and ppmsubpixels\r
-                 drawonlyshapes              convert everything to shapes (currently broken)\r
-                 ignoredraworder             allow to perform a few optimizations for creating smaller SWFs\r
-                 linksopennewwindow          make links open a new browser window\r
-                 linktarget                  target window name of new links\r
-                 linkcolor=<color)           color of links (format: RRGGBBAA)\r
-                 linknameurl                 Link buttons will be named like the URL they refer to (handy for iterating through links with actionscript)\r
-                 storeallcharacters          don't reduce the fonts to used characters in the output file\r
-                 enablezlib                  switch on zlib compression (also done if flashversion>=7)\r
-                 bboxvars                    store the bounding box of the SWF file in actionscript variables\r
-                 dots                        Take care to handle dots correctly\r
-                 reordertags=0/1             (default: 1) perform some tag optimizations\r
-                 internallinkfunction=<name> when the user clicks a internal link (to a different page) in the converted file, this actionscript function is called\r
-                 externallinkfunction=<name> when the user clicks an external link (e.g. http://www.foo.bar/) on the converted file, this actionscript function is called\r
-                 disable_polygon_conversion  never convert strokes to polygons (will remove capstyles and joint styles)\r
-                 caplinewidth=<width>        the minimum thichness a line needs to have so that capstyles become visible (and are converted)\r
-                 insertstop                  put an ActionScript "STOP" tag in every frame\r
-                 protect                     add a "protect" tag to the file, to prevent loading in the Flash editor\r
-                 flashversion=<version>      the SWF fileversion (6)\r
-                 framerate=<fps>             SWF framerate\r
-                 minlinewidth=<width>        convert horizontal/vertical boxes smaller than this width to lines (0.05)\r
-                 simpleviewer                Add next/previous buttons to the SWF\r
-                 animate                     insert a showframe tag after each placeobject (animate draw order of PDF files)\r
-                 jpegquality=<quality>       set compression quality of jpeg images\r
-                 splinequality=<value>       Set the quality of spline convertion to value (0-100, default: 100).\r
-                 disablelinks                Disable links.\r
-                */\r
-\r
-               if (file_exists($this->out . $prefix . $page . '.swf')) {\r
-                       unlink($this->out . $prefix . $page . '.swf');\r
-               }\r
-\r
-               if (!in_array($method, array(self::BARBARE_PNM, self::BARBARE_GS))) {\r
-                       if (in_array($version, array('legacy', 'stable', 'latest', 'git'))) {\r
-                               $program = '/usr/local/swftools/' . $version . '/bin/pdf2swf';\r
-                       } else {\r
-                               $program = 'pdf2swf';\r
-                       }\r
-\r
-                       $pdf2swf = new cubeCommandLine($program, null, true);\r
-                       $pdf2swf->setPath(CONVERTER_PATH);\r
-\r
-                       $pdf2swf->setArg('p', $page);\r
-\r
-                       if ($method == self::NORMAL) {\r
-                               // Default\r
-                               $multiply = 1;\r
-                       } elseif ($method == self::FLATTEN) {\r
-                               $pdf2swf->setArg('flatten');\r
-                               $multiply = 1;\r
-                       } elseif ($method == self::POLY2BITMAP) {\r
-                               // Raster graphics, keep texts\r
-                               $pdf2swf->setArg('set poly2bitmap');\r
-                               $multiply = self::$resolution2multiply[$resolution];\r
-                               $pdf2swf->setArg('set multiply', $multiply);\r
-                       } elseif ($method == self::BITMAP) {\r
-                               // Raster all\r
-                               $pdf2swf->setArg('set bitmap');\r
-                               $multiply = self::$resolution2multiply[$resolution];\r
-                               $pdf2swf->setArg('set multiply', $multiply);\r
-                       }\r
-                       // $pdf2swf->setManualArg('-v');\r
-                       $pdf2swf->setArg('T', 10);\r
-                       $pdf2swf->setArg('set reordertags', '0');\r
-                       if ($storeAllChars) {\r
-                               $pdf2swf->setArg('fonts');\r
-                               $pdf2swf->setArg('set storeallcharacters');\r
-                       }\r
-                       if (DEV) {\r
-                               $pdf2swf->setArg('F', 'C:/Windows/Fonts');\r
-                       } else {\r
-                               $pdf2swf->setArg('F', '/home/typo/fonts');\r
-                       }\r
-                       $pdf2swf->setArg('set subpixels', $resolution / 72);\r
-                       $pdf2swf->setArg('set jpegquality', $quality);\r
-                       $pdf2swf->setArg('set disablelinks');\r
-                       $pdf2swf->setArg('set dots');\r
-                       if ($version == 'git') {\r
-                               $pdf2swf->setArg(null, '-T7');\r
-                               $pdf2swf->setArg('set alignfonts');\r
-                       }\r
-                       $pdf2swf->setArg(null, $this->cropped);\r
-                       $pdf2swf->setArg('output', $this->out . $prefix . '%.swf');\r
-                       $pdf2swf->execute();\r
-\r
-                       if ($version == 'git') {\r
-                               $f = $this->out . $prefix . $page . '.swf';\r
-                               $combine = new cubeCommandLine('swfcombine');\r
-                               $combine->setArg('d');\r
-                               $combine->setArg(null, '-F9');\r
-                               $combine->setArg(null, $f);\r
-                               $combine->setArg('o', $f);\r
-                               $combine->execute();\r
-                       }\r
-\r
-                       $this->addToLog($pdf2swf, true, $page);\r
-               } else {\r
-                       $this->pdf2swfBarbare($page, $resolution, $quality, $method);\r
-               }\r
-       }\r
-\r
-       protected function makeAS3($page) {\r
-               $swffile = $this->out . 'p' . $page . '.swf';\r
-\r
-               $swfcombine = new cubeCommandLine('swfcombine');\r
-               $swfcombine->setPath(CONVERTER_PATH);\r
-               $swfcombine->setArg('merge');\r
-               $swfcombine->setArg('stack1');\r
-               $swfcombine->setArg('z');\r
-               $swfcombine->setManualArg('-v');\r
-               $swfcombine->setArg('o', $swffile);\r
-               $swfcombine->setArg(null, ROOT . '/swf/as3Container.swf');\r
-               $swfcombine->setManualArg('content=' . $swffile);\r
-               $swfcombine->execute();\r
-               $this->addToLog($swfcombine, true, $page);\r
-       }\r
-\r
-       protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4) {\r
-               // Fabrique les images\r
-\r
-               $this->addToLog('Making barbare swf', true, $page);\r
-\r
-               if ($method == self::BARBARE_PNM) {\r
-                       $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'PNM');\r
-               } elseif ($method == self::BARBARE_GS) {\r
-                       $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'GS');\r
-               }\r
-\r
-               $dim = getimagesize($this->out . 'barbare' . $page . '.jpg');\r
-\r
-               // A partir des images, on crée les swf\r
-               $jpeg2swf = new cubeCommandLine('jpeg2swf');\r
-               $jpeg2swf->setPath(CONVERTER_PATH);\r
-               $jpeg2swf->setArg('--quality', $quality);\r
-               $jpeg2swf->setArg('--output', $this->out . 'p' . $page . '.swf');\r
-               $jpeg2swf->setArg('--flashversion', 10);\r
-               $jpeg2swf->setArg('--width', $dim[0] * (72 / $resolution));\r
-               $jpeg2swf->setArg('--height', $dim[1] * (72 / $resolution));\r
-               $jpeg2swf->setArg('--fit-to-movie');\r
-               $jpeg2swf->setArg(null, $this->out . 'barbare' . $page . '.jpg');\r
-               $jpeg2swf->execute();\r
-               $this->addToLog($jpeg2swf, true, $page);\r
-               // Suppression du jpeg\r
-               @unlink($this->out . '/barbare' . $page . '.jpg', true, $page);\r
-\r
-               $pdf2swf = new cubeCommandLine('pdf2swf', null, true);\r
-               $pdf2swf->setPath(CONVERTER_PATH);\r
-               $pdf2swf->setArg('set poly2bitmap');\r
-               $pdf2swf->setArg('p', $page);\r
-               $pdf2swf->setArg('stop');\r
-               $pdf2swf->setArg('T', 10);\r
-               $pdf2swf->setArg('set reordertags', '0');\r
-               $pdf2swf->setArg('fonts');\r
-               $pdf2swf->setArg('set storeallcharacters');\r
-               if (DEV) {\r
-                       $pdf2swf->setArg('F', 'C:/Windows/Fonts');\r
-               } else {\r
-                       $pdf2swf->setArg('F', '/home/typo/fonts');\r
-               }\r
-               if (file_exists($this->out . 't' . $page . '.swf')) {\r
-                       unlink($this->out . 't' . $page . '.swf');\r
-               }\r
-               $pdf2swf->setArg('set subpixels', '0.01');\r
-               $pdf2swf->setArg('set jpegquality', '1');\r
-               $pdf2swf->setArg('set disablelinks');\r
-               $pdf2swf->setArg(null, $this->cropped);\r
-               $pdf2swf->setArg('output', $this->out . 't' . $page . '.swf');\r
-               $pdf2swf->execute();\r
-               $this->addToLog($pdf2swf, true, $page);\r
-\r
-               return '';\r
-       }\r
-\r
-       public function resetLog() {\r
-               unlink($this->log . '/commons.log.gz');\r
-       }\r
-\r
-       public function addToLog($cl, $output = true, $page = null) {\r
-               if ($cl instanceof cubeCommandLine) {\r
-                       $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n";\r
-                       if ($output) {\r
-                               $c .= $cl->output . "\n\n";\r
-                       }\r
-               } elseif (is_string($cl)) {\r
-                       $c = '--- ' . "\n\n";\r
-                       $c .= $cl . "\n\n";\r
-               }\r
-\r
-               if (is_null($page)) {\r
-                       $pointer = fopen($this->log . '/commons.log', 'ab');\r
-               } else {\r
-                       $pointer = fopen($this->log . '/p' . $page . '.log', 'ab');\r
-               }\r
-\r
-               fwrite($pointer, $c);\r
-               fclose($pointer);\r
-       }\r
-\r
-       public function __destruct() {\r
-               \r
-       }\r
-\r
-}\r
-\r
+<?php
+
+/**
+ * wsDocument
+ *
+ * @package
+ * @author Vincent
+ * @copyright Copyright (c) 2010
+ * @version $Id$
+ * @access public
+ */
+class wsDocument extends cubeMetier {
+
+       protected $document_id;
+       protected $file;
+       protected $proprietaire;
+       protected $pages;
+       protected $trim;
+       protected $date;
+       protected $localInfos;
+       protected $generalInfos;
+       protected $conversionInfos;
+       protected $bookmarks;
+       protected $numberSections;
+       protected $localHash;
+       protected $version;
+       // Crop & cut
+       protected $autocrop;
+       protected $manualcrop;
+       protected $autocut;
+       protected $manualcut;
+       // Files
+       protected $out;
+       protected $in;
+       protected $html;
+       protected $uncompressed;
+       protected $log;
+       protected $common_log_pointer;
+       protected $pages_log_pointers;
+       protected $infos;
+       protected $cropped;
+       protected $rgb;
+
+       const NORMAL = 0;
+       const FLATTEN = 1;
+       const POLY2BITMAP = 2;
+       const BITMAP = 3;
+       const BARBARE_PNM = 4;
+       const BARBARE_GS = 5;
+       const MAX = 5;
+       const PNM_FILL = 2;
+
+       protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);
+       // Number section styles
+       protected static
+                       $numberStyles = array('NoNumber' => 'no', 'DecimalArabicNumerals' => 'decimal',
+               'UppercaseRomanNumerals' => 'roman_up', 'LowercaseRomanNumerals' => 'roman_low',
+               'UppercaseLetters' => 'letters_up', 'LowercaseLetters' => 'letters_low');
+
+       public function init() {
+               $this->out = WS_DOCS . '/' . $this->document_id . '/';
+               $this->log = $this->out . '/logs/';
+               $this->html = $this->out . '/html/';
+               $this->in = $this->out . 'original.pdf';
+               $this->uncompressed = $this->out . 'uncompressed.pdf';
+               $this->infos = $this->out . 'infos.txt';
+               if (!file_exists($this->out)) {
+                       mkdir($this->out, 0755, true);
+                       mkdir($this->log, 0755);
+               }
+               if (!file_exists($this->html)) {
+                       mkdir($this->html, 0755);
+               }
+               $this->cropped = $this->out . 'crop.pdf';
+               $this->pages_log_pointers = array();
+
+               if (is_null($this->conversionInfos)) {
+                       $this->conversionInfos = new wsDocumentConversionInfos();
+               }
+       }
+
+       public function copyOriginalFromUpload($tmp_file) {
+               move_uploaded_file($tmp_file, $this->in);
+       }
+
+       public function copyOriginalFromOlderVersion() {
+               if (!file_exists($this->in)) {
+                       copy('http://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);
+               }
+       }
+
+       public function extractFonts() {
+               $extractor = new wsPDFFontExtractor($this->out, $this);
+               $extractor->extract();
+       }
+
+       public function getInfos($in = null, $force = false) {
+               if (is_null($in)) {
+                       $in = $this->in;
+               }
+
+               $fwstk = new cubeCommandLine('fwstk');
+               $fwstk->setPath(CONVERTER_PATH);
+               $fwstk->setArg('--input ' . $in);
+               $fwstk->setArg('--infos');
+               $fwstk->execute();
+               $this->addToLog($fwstk);
+               $out = $fwstk->output;
+
+               $pdfinfo = new cubeCommandLine('pdfinfo');
+               $pdfinfo->setPath(CONVERTER_PATH);
+               $pdfinfo->setArg('-box');
+               $pdfinfo->setArg('f', 1);
+               $pdfinfo->setArg('l', 100000);
+               $pdfinfo->setArg(null, $in);
+               $pdfinfo->execute();
+               $this->addToLog($pdfinfo);
+               $out.="\n";
+               $out.=$pdfinfo->output;
+
+               $this->parseInfos($out);
+
+               $this->conversionInfos->setPageNumber($this->generalInfos['pages']);
+
+               file_put_contents($this->infos, $out);
+               $this->findCutDisposition();
+       }
+
+       public function findCutDisposition() {
+               $this->detectSpreads();
+               $this->detectPageDifferences();
+       }
+
+       protected function detectPageDifferences() {
+               // Vérifie si la cropbox et la trimbox sont identiques pour toutes les pages
+               $difference = false;
+               foreach ($this->generalInfos['page'] as $page => $infos) {
+                       if (!isset($infos['crop']) || !isset($infos['crop'])) {
+                               continue;
+                       }
+                       if ($infos['crop'] != $infos['trim']) {
+                               $difference = true;
+                       }
+               }
+               if (!$difference) {
+                       return false;
+               }
+               // Vérifie si la trimbox définie toutes les pages de la même taille
+               $heights = array();
+               $widths = array();
+               foreach ($this->generalInfos['page'] as $page => $infos) {
+                       $heights[] = round($infos['trim']->height);
+                       $widths[] = round($infos['trim']->width);
+               }
+               $heights = array_unique($heights);
+               $widths = array_unique($widths);
+               if (count($heights) == 1 && count($widths) == 1) {
+                       $this->autocrop = 'trim';
+                       $this->manualcrop = false;
+               } else {
+                       $this->autocrop = false;
+                       $this->manualcrop = true;
+               }
+       }
+
+       protected function detectSpreads() {
+               // Détection des spreads
+
+               $this->autocut = false;
+               $this->manualcut = false;
+               if ($this->generalInfos['pages'] <= 2) {
+                       return;
+               }
+
+               foreach ($this->generalInfos['page'] as $page => $infos) {
+                       if ($page == 1) {
+                               $first = $infos['size'];
+                       } elseif ($page == $this->generalInfos['pages']) {
+                               $last = $infos['size'];
+                       } elseif ($page == 2) {
+                               $second = $infos['size'];
+                       }
+               }
+
+               if ($first == $last && $last == $second) {
+                       $ratio = $first[0] / $first[1];
+                       $this->autocut = false;
+                       if ($ratio <= 1) {
+                               $this->manualcut = false;
+                       } elseif ($ratio >= 6) {
+                               $this->manualcut = 'L8';
+                       } elseif ($ratio >= 3) {
+                               $this->manualcut = 'L4';
+                       } elseif ($ratio >= 2) {
+                               $this->manualcut = 'L3';
+                       } else {
+                               $this->manualcut = '14-23';
+                       }
+                       return;
+               }
+               $this->manualcut = false;
+               if (self::compareSizes($last, $first) && cubeMath::compare($first[0] * 2, $second[0], 0.9)) {
+                       $this->autocut = '1-23-4';
+               }
+               if (cubeMath::compare($first[0] * 2, $second[0], 0.9) && self::compareSizes($last, $second)) {
+                       $this->autocut = '1-23';
+               }
+
+               $this->addToLog('Detect Spreads : Manual cut ' . $this->manualcut . ' ; Auto cut : ' . $this->autocut);
+       }
+
+       public static function compareSizes($x, $y, $tolerance = 0.9) {
+               return cubeMath::compare($x[0], $y[0], $tolerance) && cubeMath::compare($x[1], $y[1], $tolerance);
+       }
+
+       public function parseInfos($data) {
+               // This function get general infos (pages sizes, boxes, number sections and
+               // bookmarks
+               // Init arrays
+               $this->generalInfos = array();
+               $this->generalInfos['size'] = array(0, 0);
+               $this->bookmarks = array();
+               $this->numberSections = '';
+               $bookmark_id = 0;
+
+               $res['size'] = array(0, 0);
+               $lines = explode("\n", $data);
+               foreach ($lines as $line) {
+                       $line = trim(cubeText::condenseWhite($line));
+                       $e = explode(':', $line, 2);
+                       $k = trim($e[0]);
+                       if (count($e) < 2) {
+                               continue;
+                       }
+                       $v = trim($e[1]);
+                       if ($k == 'Pages' || $k == 'NumberOfPages') {
+                               $this->pages = $this->generalInfos['pages'] = $v;
+                               $this->generalInfos['page'] = array();
+                               for ($i = 1; $i <= $this->pages; $i++) {
+                                       $this->generalInfos['page'][$i] = array();
+                               }
+                       } elseif (preg_match('|Page\s+([0-9]+)\s+(.*)Box:\s+([0-9.]*)\s+([0-9.]*)\s+([0-9.]*)\s+([0-9.]*)|iu', $line, $m)) {
+                               $this->generalInfos['page'][$m[1]][strtolower($m[2])] = new wsBox($m[3], $m[4], $m[5], $m[6]);
+                       } elseif (preg_match('|Page\s+([0-9]+)\s+size:\s+([0-9.]*)[pts[:space:]]+x\s+([0-9.]*)\s+pts|iu', $line, $m)) {
+                               $this->generalInfos['page'][$m[1]]['size'] = array($m[2], $m[3]);
+                               if ($m[1] == 1) {
+                                       $this->generalInfos['size'][0] = $m[2];
+                                       $this->generalInfos['size'][1] = $m[3];
+                               }
+                       } elseif ($k == 'BookmarkTitle') {
+                               $this->bookmarks[$bookmark_id] = array('titre' => str_replace('&#13;', '', trim($v)));
+                       } elseif ($k == 'BookmarkLevel') {
+                               $this->bookmarks[$bookmark_id]['level'] = $v;
+                       } elseif ($k == 'BookmarkPageNumber') {
+                               $this->bookmarks[$bookmark_id]['page'] = $v;
+                               $bookmark_id++;
+                       } elseif ($k == 'NumberSections') {
+                               $this->numberSections = $v;
+                       }
+               }
+
+               return $res;
+       }
+
+       public function getPagesNumber() {
+               $this->getInfos();
+               return $this->generalInfos['pages'];
+       }
+
+       public function globalOperations() {
+               $this->getInfos();
+               if ($this->CropAndCut()) {
+                       $this->getInfos($this->cropped, true);
+               }
+               $this->getLinksAndTexts();
+       }
+
+       public function CropAndCut() {
+               if (!$this->isCropped()) {
+                       copy($this->in, $this->cropped);
+                       return false;
+               }
+               if ($this->autocrop == 'trim') {
+                       $this->trimDocument();
+               } else {
+                       copy($this->in, $this->cropped);
+               }
+
+               if ($this->autocut) {
+                       $this->cutDocument($this->autocut);
+                       return true;
+               }
+               return false;
+       }
+
+       public function cutDocument($mode) {
+               $fwstk = new cubeCommandLine('fwstk');
+               $fwstk->setPath(CONVERTER_PATH);
+               $fwstk->setArg('--input ' . $this->in);
+               $fwstk->setArg('--cut ' . $mode);
+               $fwstk->setArg('--output ' . $this->cropped);
+               $fwstk->execute();
+               $this->addToLog($fwstk);
+       }
+
+       public function trimDocument() {
+               $fwstk = new cubeCommandLine('fwstk');
+               $fwstk->setPath(CONVERTER_PATH);
+               $fwstk->setArg('--input ' . $this->in);
+               $fwstk->setArg('--trim');
+               $fwstk->setArg('--output ' . $this->cropped);
+               $fwstk->execute();
+               $this->addToLog($fwstk);
+       }
+
+       public function processOnePage($page, $force = true) {
+               if ($force) {
+                       $this->addToLog('Processing page #' . $page);
+                       $this->makeMiniShot($page);
+                       $this->makeSWFFiles($page);
+                       $this->makeHTML5Files($page);
+               }
+       }
+
+       public function processAllPages() {
+               for ($i = 1; $i <= $this->generalInfos['pages']; $i++) {
+                       $this->processOnePage($i);
+               }
+               $this->optimizeSVG();
+       }
+
+       public function optimizeSVG() {
+
+
+
+               $scour = new cubeCommandLine('scour.php');
+               $scour->setPath(CONVERTER_PATH);
+               $scour->setNohup(true);
+               $scour->setArg(null, $this->html);
+               $scour->execute();
+       }
+
+       public function processRange($pages) {
+               foreach ($pages as $i) {
+                       $this->processOnePage($i);
+               }
+               $this->optimizeSVG();
+       }
+
+       public function getLinksAndTexts() {
+               $fwstk = new cubeCommandLine('fwstk');
+               $fwstk->setPath(CONVERTER_PATH);
+               $fwstk->setArg('--input ' . $this->cropped);
+               $fwstk->setArg('--extractTexts ' . $this->out . '%s%d.txt');
+               $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');
+               $fwstk->execute();
+               $this->addToLog($fwstk);
+
+               /* $fwstk = new cubeCommandLine('fwstk');
+                 $fwstk->setPath(CONVERTER_PATH);
+                 $fwstk->setArg('--input ' . $this->cropped);
+                 $fwstk->setArg('--layout ' . $this->html . 'p%d.layout');
+                 $fwstk->setArg('--cmaps ' . $this->html);
+                 $fwstk->setArg('--fonts' . $this->out . 'fonts/web/');
+                 $fwstk->execute();
+                 $this->addToLog($fwstk); */
+       }
+
+       public function makeMiniShot($page) {
+               $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'PNM');
+       }
+
+       public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') {
+               // Make thumbs of $w width
+               // resolution 72 make 1pt=1px
+               $width = $this->generalInfos['size'][0];
+               $ratio = $width / $w;
+               $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
+       }
+
+       public function makeShotFixedHeight($page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM') {
+               // Make thumbs of $w height
+               // resolution 72 make 1pt=1px
+               $height = $this->generalInfos['size'][1];
+               $ratio = $height / $h;
+               $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
+       }
+
+       public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null) {
+               $error = false;
+               if (is_null($in)) {
+                       $in = $this->cropped;
+               }
+               // Delete all old files
+               $res = $this->out . $prefix . $page . '.jpg';
+               if (file_exists($res)) {
+                       @unlink($res);
+               }
+
+               if ($method == 'GS') {
+                       $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);
+               } elseif ($method == 'PNM') {
+                       $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);
+               }
+               // Test the result by checking all files
+               if (!file_exists($res)) {
+                       $error = true;
+               }
+               // If error, we try to make thumbs with other method
+               if ($error) {
+                       if ($method == 'GS') {
+                               $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);
+                       } elseif ($method == 'PNM') {
+                               $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);
+                       }
+               }
+       }
+
+       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null) {
+               if (is_null($in)) {
+                       $in = $this->cropped;
+               }
+               // Fabrication des thumbanails avec ghostscript
+               $gs = new cubeCommandLine('gs', null, true);
+               $gs->setPath(CONVERTER_PATH);
+               $gs->setEnv('GS_FONTPATH', FONT_PATH);
+               $gs->setArg('-dBATCH');
+               $gs->setArg('-dNOPAUSE');
+               $gs->setArg('-dNOPROMPT');
+               // Antialias
+               $gs->setArg('-dDOINTERPOLATE');
+               $gs->setArg('-dTextAlphaBits=' . $antialiasing);
+               $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);
+               // Device
+               $gs->setArg('-sDEVICE=jpeg');
+               // Dispotion & colors
+               // $gs->setArg('-dUseCIEColor');
+               $gs->setArg('-dAutoRotatePages=/None');
+               $gs->setArg('-dUseCropBox');
+               // Resolution & Quality
+               $gs->setArg('-r' . round($resolution));
+               $gs->setArg('-dJPEGQ=' . $quality);
+               // Performances
+               $gs->setArg('-dNumRenderingThreads=4');
+               // Page range
+               $gs->setArg('-dFirstPage=' . $page);
+               $gs->setArg('-dLastPage=' . $page);
+               // Files
+               $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . $page . '.jpg');
+
+               $gs->setArg(null, $in);
+               $gs->execute();
+               $this->addToLog($gs, true, $page);
+       }
+
+       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true) {
+               if (is_null($in)) {
+                       $in = $this->cropped;
+               }
+
+               $tmp = cubeFiles::tempnam();
+
+               $antialiasing = $antialiasing ? 'yes' : 'no';
+               $freetype = $texts ? 'yes' : 'no';
+               $resolution = $resolution;
+               // Exporte les fichiers
+               $pdftoppm = new cubeCommandLine('pdftoppm', null, true);
+               $pdftoppm->setPath(CONVERTER_PATH);
+
+               $pdftoppm->setArg('f', $page);
+               $pdftoppm->setArg('l', $page);
+               $pdftoppm->setArg('-cropbox');
+               $pdftoppm->setArg('-freetype ' . $freetype);
+               $pdftoppm->setArg('-singlefile');
+               $pdftoppm->setArg('-aa ' . $antialiasing);
+               $pdftoppm->setArg('-aaVector ' . $antialiasing);
+               $pdftoppm->setArg('r', $resolution);
+               $pdftoppm->setArg(null, $in);
+               $pdftoppm->setArg(null, $tmp);
+               $pdftoppm->execute();
+               $this->addToLog($pdftoppm, true, $page);
+
+               $tmp.='.ppm';
+
+               $jpegfile = $this->out . $prefix . $page . '.jpg';
+
+               if (file_exists($tmp)) {
+                       $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false);
+                       $pnmtojpeg->setArg('-quality ' . $quality);
+                       $pnmtojpeg->setArg(null, $tmp);
+                       $pnmtojpeg->execute();
+                       $this->addToLog($pnmtojpeg, false, $page);
+
+                       unlink($tmp);
+               }
+       }
+
+       protected function isCropped() {
+               return $this->autocrop || $this->manualcrop || $this->autocut || $this->manualcut;
+       }
+
+       public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version = null) {
+               $conversionSettings = $this->conversionInfos->pages[$page];
+               if (is_null($storeAllChars)) {
+                       $storeAllChars = true;
+               }
+               if (is_null($resolution)) {
+                       $resolution = $conversionSettings->resolution;
+               }
+               if (is_null($method)) {
+                       $method = $conversionSettings->method;
+               }
+               if (is_null($quality)) {
+                       $quality = $conversionSettings->quality;
+               }
+               if (is_null($maxObjects)) {
+                       $maxObjects = $conversionSettings->objects;
+               }
+               if (is_null($version)) {
+                       $version = isset($conversionSettings->version) ? $conversionSettings->version : 'stable';
+               }
+
+               if ($maxObjects <= 1) {
+                       $method = self::POLY2BITMAP;
+               }
+
+               // Pour les fichiers croppés, on utilise la méthode flatten qui ne prends
+               // pas en compte les objets hors de la box
+               if ($this->isCropped()) {
+                       // $method = max($method, self::FLATTEN);
+               }
+
+               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, 'p', $version);
+               if ($method < self::BARBARE_PNM) {
+                       // Analyse de la sortie pour détecter des typos manquantes
+                       $overflow = false;
+                       $overflowObjects = false;
+                       $written = false;
+                       $missing_fonts = array();
+                       if (file_exists($out)) {
+                               $fp = fopen($out, 'rb');
+                               while ($line = fgets($fp)) {
+                                       if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) {
+                                               $missing_fonts[] = $matches[1];
+                                       } elseif (stristr($line, 'ID Table overflow')) {
+                                               $overflow = true;
+                                       } elseif (stristr($line, 'NOTICE  SWF written')) {
+                                               $written = true;
+                                       } elseif (stristr($line, 'NOTICE  Writing SWF file')) {
+                                               $written = true;
+                                       }
+                               }
+                       }
+                       if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {
+                               $written = true;
+                       }
+                       // On teste si le fichier est écrit et qu'il a été généré par le premier niveau
+                       if ($method < self::POLY2BITMAP && $written) {
+                               $overflowObjects = $this->checkObjectsNumber($this->out . 'p' . $page . '.swf', $maxObjects, $page);
+                       }
+
+                       if (!$written || $overflow || $overflowObjects) {
+                               if ($method == self::MAX) {
+                                       return;
+                               }
+                               $nextMethod = $method + 1;
+                               return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $nextMethod, $version);
+                       }
+               }
+       }
+
+       public function makeHTML5Files($page) {
+               // Then make HD background shots
+               $resolutions = array(300 => 85, 150 => 85, 36 => 85);
+               foreach ($resolutions as $r => $q) {
+                       $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false);
+                       $this->makeShotPNM($page, 'html/t' . $r . '-', $r, $q, 4, null, true);
+               }
+               $this->makeSVGFile($page);
+       }
+
+       public function makeSVGFile($page) {
+               $svgFile = $this->out . '/html/p' . $page . '.svg';
+               $svgOpt = $this->out . '/html/o' . $page . '.svg';
+
+               $pdftocairo = new cubeCommandLine('pdftocairo');
+               $pdftocairo->setPath(CONVERTER_PATH);
+               $pdftocairo->setArg('f', $page);
+               $pdftocairo->setArg('l', $page);
+               $pdftocairo->setArg(null, '-svg');
+               $pdftocairo->setArg(null, '-cropbox');
+               $pdftocairo->setArg(null, $this->cropped);
+               $pdftocairo->setArg(null, $svgFile);
+               $pdftocairo->execute();
+               $this->addToLog($pdftocairo, true, $page);
+
+               $this->_cleanSVG($svgFile);
+       }
+
+       protected function _cleanSVG($svgFile) {
+               $svg = new DOMDocument();
+               $svg->preserveWhiteSpace = false;
+               $svg->load($svgFile);
+
+               // Operations to delete
+               $xpath = new DOMXPath($svg);
+               $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
+               $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');
+               $xpath->registerNamespace("php", "http://php.net/xpath");
+               $xpath->registerPhpFunctions('has_not_text');
+               $toDelete = array('//svg:defs/svg:clipPath',
+                       '//svg:defs/svg:image',
+                       '//svg:defs/svg:pattern',
+                       '/svg:svg/svg:g/svg:g[not(svg:use[@xlink:href])]',
+                       '/svg:svg/svg:g/svg:path',
+                       '/svg:svg/svg:g/svg:rect',
+               );
+
+               global $svglog;
+               $svglog = array('XPATH : ' . print_r($xpath, true));
+               foreach ($toDelete as $q) {
+                       $list = $xpath->query($q);
+                       $svglog[] = "Evaluate xpath query " . $q;
+                       $svglog[] = 'Give ' . $list->length . ' results';
+                       $svglog[] = 'Deleting Nodes in ' . print_r($list, true);
+                       if (count($list)) {
+                               foreach ($list as $node) {
+
+                                       /* @var $node DOMNode */
+                                       $parent = $node->parentNode;
+                                       $parent->removeChild($node);
+                               }
+                       }
+               }
+
+               $this->addToLog(implode("\n", $svglog), false, $page);
+               file_put_contents($svgFile, $svg->saveXML());
+       }
+
+       protected function checkObjectsNumber($file, $maxObjects, $page) {
+               $swfdump = new cubeCommandLine('swfdump', null, true);
+               $swfdump->setPath(CONVERTER_PATH);
+               $swfdump->setArg(null, $file);
+               $swfdump->execute();
+               $this->addToLog($swfdump, true, $page);
+
+               str_replace('[01a]', '', $swfdump->output, $nbObjects);
+               if ($nbObjects > $maxObjects) {
+                       return true;
+               }
+               return false;
+       }
+
+       protected function dumpSWF($page, $prefix = 'p') {
+               $swfdump = new cubeCommandLine('/usr/local/swftools/special-swfdump/bin/swfdump', null, true);
+               $swfdump->setPath(CONVERTER_PATH);
+               $swfdump->setArg('t');
+               $swfdump->setArg('p');
+               $swfdump->setArg('F');
+               $swfdump->setArg(null, $this->out . $prefix . $page . '.swf');
+               $swfdump->execute();
+               $this->addToLog($swfdump, false, $page);
+               return $swfdump->output;
+       }
+
+       /**
+        * wsDocument::pdf2swf()
+        *
+        * @param mixed $page
+        * @param integer $resolution
+        * @param integer $quality
+        * @param mixed $storeAllChars
+        * @param integer $method
+        * @return
+        */
+       protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version = 'stable') {
+               /*
+                 -h , --help                    Print short help message and exit
+                 -V , --version                 Print version info and exit
+                 -o , --output file.swf         Direct output to file.swf. If file.swf contains '%' (file%.swf), then each page goes to a seperate file.
+                 -p , --pages range             Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or
+                 -P , --password password       Use password for deciphering the pdf.
+                 -v , --verbose                 Be verbose. Use more than one -v for greater effect.
+                 -z , --zlib                    Use Flash 6 (MX) zlib compression.
+                 -i , --ignore                  Allows pdf2swf to change the draw order of the pdf. This may make the generated
+                 -j , --jpegquality quality     Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
+                 -s , --set param=value         Set a SWF encoder specific parameter.  See pdf2swf -s help for more information.
+                 -w , --samewindow              When converting pdf hyperlinks, don't make the links open a new window.
+                 -t , --stop                    Insert a stop() command in each page.
+                 -T , --flashversion num        Set Flash Version in the SWF header to num.
+                 -F , --fontdir directory       Add directory to the font search path.
+                 -b , --defaultviewer           Link a standard viewer to the swf file.
+                 -l , --defaultloader           Link a standard preloader to the swf file which will be displayed while the main swf is loading.
+                 -B , --viewer filename         Link viewer filename to the swf file.
+                 -L , --preloader filename      Link preloader filename to the swf file.
+                 -q , --quiet                   Suppress normal messages.  Use -qq to suppress warnings, also.
+                 -S , --shapes                  Don't use SWF Fonts, but store everything as shape.
+                 -f , --fonts                   Store full fonts in SWF. (Don't reduce to used characters).
+                 -G , --flatten                 Remove as many clip layers from file as possible.
+                 -I , --info                    Don't do actual conversion, just display a list of all pages in the PDF.
+                 -Q , --maxtime n               Abort conversion after n seconds. Only availableon Unix.
+
+                 PDF device global parameters:
+                 -----------------------------
+                 fontdir=<dir>     a directory with additional fonts
+                 font=<filename>   an additional font filename
+                 pages=<range>     the range of pages to convert (example: pages=1-100,210-)
+                 zoom=<dpi>        the resultion (default: 72)
+                 languagedir=<dir> Add an xpdf language directory
+                 multiply=<times>  Render everything at <times> the resolution
+                 poly2bitmap       Convert graphics to bitmaps
+                 bitmap            Convert everything to bitmaps
+
+                 SWF Parameters :
+                 ----------------
+                 SWF layer options :
+                 -------------------
+
+                 jpegsubpixels=<pixels>      resolution adjustment for jpeg images (same as jpegdpi, but in pixels)
+                 ppmsubpixels=<pixels        resolution adjustment for  lossless images (same asppmdpi, but in pixels)
+                 subpixels=<pixels>          shortcut for setting both jpegsubpixels and ppmsubpixels
+                 drawonlyshapes              convert everything to shapes (currently broken)
+                 ignoredraworder             allow to perform a few optimizations for creating smaller SWFs
+                 linksopennewwindow          make links open a new browser window
+                 linktarget                  target window name of new links
+                 linkcolor=<color)           color of links (format: RRGGBBAA)
+                 linknameurl                 Link buttons will be named like the URL they refer to (handy for iterating through links with actionscript)
+                 storeallcharacters          don't reduce the fonts to used characters in the output file
+                 enablezlib                  switch on zlib compression (also done if flashversion>=7)
+                 bboxvars                    store the bounding box of the SWF file in actionscript variables
+                 dots                        Take care to handle dots correctly
+                 reordertags=0/1             (default: 1) perform some tag optimizations
+                 internallinkfunction=<name> when the user clicks a internal link (to a different page) in the converted file, this actionscript function is called
+                 externallinkfunction=<name> when the user clicks an external link (e.g. http://www.foo.bar/) on the converted file, this actionscript function is called
+                 disable_polygon_conversion  never convert strokes to polygons (will remove capstyles and joint styles)
+                 caplinewidth=<width>        the minimum thichness a line needs to have so that capstyles become visible (and are converted)
+                 insertstop                  put an ActionScript "STOP" tag in every frame
+                 protect                     add a "protect" tag to the file, to prevent loading in the Flash editor
+                 flashversion=<version>      the SWF fileversion (6)
+                 framerate=<fps>             SWF framerate
+                 minlinewidth=<width>        convert horizontal/vertical boxes smaller than this width to lines (0.05)
+                 simpleviewer                Add next/previous buttons to the SWF
+                 animate                     insert a showframe tag after each placeobject (animate draw order of PDF files)
+                 jpegquality=<quality>       set compression quality of jpeg images
+                 splinequality=<value>       Set the quality of spline convertion to value (0-100, default: 100).
+                 disablelinks                Disable links.
+                */
+
+               if (file_exists($this->out . $prefix . $page . '.swf')) {
+                       unlink($this->out . $prefix . $page . '.swf');
+               }
+
+               if (!in_array($method, array(self::BARBARE_PNM, self::BARBARE_GS))) {
+                       if (in_array($version, array('legacy', 'stable', 'latest', 'git'))) {
+                               $program = '/usr/local/swftools/' . $version . '/bin/pdf2swf';
+                       } else {
+                               $program = 'pdf2swf';
+                       }
+
+                       $pdf2swf = new cubeCommandLine($program, null, true);
+                       $pdf2swf->setPath(CONVERTER_PATH);
+
+                       $pdf2swf->setArg('p', $page);
+
+                       if ($method == self::NORMAL) {
+                               // Default
+                               $multiply = 1;
+                       } elseif ($method == self::FLATTEN) {
+                               $pdf2swf->setArg('flatten');
+                               $multiply = 1;
+                       } elseif ($method == self::POLY2BITMAP) {
+                               // Raster graphics, keep texts
+                               $pdf2swf->setArg('set poly2bitmap');
+                               $multiply = self::$resolution2multiply[$resolution];
+                               $pdf2swf->setArg('set multiply', $multiply);
+                       } elseif ($method == self::BITMAP) {
+                               // Raster all
+                               $pdf2swf->setArg('set bitmap');
+                               $multiply = self::$resolution2multiply[$resolution];
+                               $pdf2swf->setArg('set multiply', $multiply);
+                       }
+                       // $pdf2swf->setManualArg('-v');
+                       $pdf2swf->setArg('T', 10);
+                       $pdf2swf->setArg('set reordertags', '0');
+                       if ($storeAllChars) {
+                               $pdf2swf->setArg('fonts');
+                               $pdf2swf->setArg('set storeallcharacters');
+                       }
+                       if (DEV) {
+                               $pdf2swf->setArg('F', 'C:/Windows/Fonts');
+                       } else {
+                               $pdf2swf->setArg('F', '/home/typo/fonts');
+                       }
+                       $pdf2swf->setArg('set subpixels', $resolution / 72);
+                       $pdf2swf->setArg('set jpegquality', $quality);
+                       $pdf2swf->setArg('set disablelinks');
+                       $pdf2swf->setArg('set dots');
+                       if ($version == 'git') {
+                               $pdf2swf->setArg(null, '-T7');
+                               $pdf2swf->setArg('set alignfonts');
+                       }
+                       $pdf2swf->setArg(null, $this->cropped);
+                       $pdf2swf->setArg('output', $this->out . $prefix . '%.swf');
+                       $pdf2swf->execute();
+
+                       if ($version == 'git') {
+                               $f = $this->out . $prefix . $page . '.swf';
+                               $combine = new cubeCommandLine('swfcombine');
+                               $combine->setArg('d');
+                               $combine->setArg(null, '-F9');
+                               $combine->setArg(null, $f);
+                               $combine->setArg('o', $f);
+                               $combine->execute();
+                       }
+
+                       $this->addToLog($pdf2swf, true, $page);
+               } else {
+                       $this->pdf2swfBarbare($page, $resolution, $quality, $method);
+               }
+       }
+
+       protected function makeAS3($page) {
+               $swffile = $this->out . 'p' . $page . '.swf';
+
+               $swfcombine = new cubeCommandLine('swfcombine');
+               $swfcombine->setPath(CONVERTER_PATH);
+               $swfcombine->setArg('merge');
+               $swfcombine->setArg('stack1');
+               $swfcombine->setArg('z');
+               $swfcombine->setManualArg('-v');
+               $swfcombine->setArg('o', $swffile);
+               $swfcombine->setArg(null, ROOT . '/swf/as3Container.swf');
+               $swfcombine->setManualArg('content=' . $swffile);
+               $swfcombine->execute();
+               $this->addToLog($swfcombine, true, $page);
+       }
+
+       protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4) {
+               // Fabrique les images
+
+               $this->addToLog('Making barbare swf', true, $page);
+
+               if ($method == self::BARBARE_PNM) {
+                       $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'PNM');
+               } elseif ($method == self::BARBARE_GS) {
+                       $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'GS');
+               }
+
+               $dim = getimagesize($this->out . 'barbare' . $page . '.jpg');
+
+               // A partir des images, on crée les swf
+               $jpeg2swf = new cubeCommandLine('jpeg2swf');
+               $jpeg2swf->setPath(CONVERTER_PATH);
+               $jpeg2swf->setArg('--quality', $quality);
+               $jpeg2swf->setArg('--output', $this->out . 'p' . $page . '.swf');
+               $jpeg2swf->setArg('--flashversion', 10);
+               $jpeg2swf->setArg('--width', $dim[0] * (72 / $resolution));
+               $jpeg2swf->setArg('--height', $dim[1] * (72 / $resolution));
+               $jpeg2swf->setArg('--fit-to-movie');
+               $jpeg2swf->setArg(null, $this->out . 'barbare' . $page . '.jpg');
+               $jpeg2swf->execute();
+               $this->addToLog($jpeg2swf, true, $page);
+               // Suppression du jpeg
+               @unlink($this->out . '/barbare' . $page . '.jpg', true, $page);
+
+               $pdf2swf = new cubeCommandLine('pdf2swf', null, true);
+               $pdf2swf->setPath(CONVERTER_PATH);
+               $pdf2swf->setArg('set poly2bitmap');
+               $pdf2swf->setArg('p', $page);
+               $pdf2swf->setArg('stop');
+               $pdf2swf->setArg('T', 10);
+               $pdf2swf->setArg('set reordertags', '0');
+               $pdf2swf->setArg('fonts');
+               $pdf2swf->setArg('set storeallcharacters');
+               if (DEV) {
+                       $pdf2swf->setArg('F', 'C:/Windows/Fonts');
+               } else {
+                       $pdf2swf->setArg('F', '/home/typo/fonts');
+               }
+               if (file_exists($this->out . 't' . $page . '.swf')) {
+                       unlink($this->out . 't' . $page . '.swf');
+               }
+               $pdf2swf->setArg('set subpixels', '0.01');
+               $pdf2swf->setArg('set jpegquality', '1');
+               $pdf2swf->setArg('set disablelinks');
+               $pdf2swf->setArg(null, $this->cropped);
+               $pdf2swf->setArg('output', $this->out . 't' . $page . '.swf');
+               $pdf2swf->execute();
+               $this->addToLog($pdf2swf, true, $page);
+
+               return '';
+       }
+
+       public function resetLog() {
+               unlink($this->log . '/commons.log.gz');
+       }
+
+       public function addToLog($cl, $output = true, $page = null) {
+               if ($cl instanceof cubeCommandLine) {
+                       $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n";
+                       if ($output) {
+                               $c .= $cl->output . "\n\n";
+                       }
+               } elseif (is_string($cl)) {
+                       $c = '--- ' . "\n\n";
+                       $c .= $cl . "\n\n";
+               }
+
+               if (is_null($page)) {
+                       $pointer = fopen($this->log . '/commons.log', 'ab');
+               } else {
+                       $pointer = fopen($this->log . '/p' . $page . '.log', 'ab');
+               }
+
+               fwrite($pointer, $c);
+               fclose($pointer);
+       }
+
+       public function __destruct() {
+
+       }
+
+}
+
 ?>
\ No newline at end of file