protected $log;\r
protected $log_pointer;\r
protected $infos;\r
- protected $textes;\r
- protected $phperrors;\r
\r
private $_basicInfos = null;\r
private $_advancedInfos = null;\r
- private $_links = array();\r
- private $_memoErrorLog;\r
\r
const NORMAL = 0;\r
const FLATTEN = 1;\r
const BARBARE_PNM = 4;\r
const BARBARE_GS = 5;\r
\r
+ protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
+\r
public function init()\r
{\r
$this->out = ROOT . '/docs/' . $this->document_id . '/';\r
$this->in = $this->out . 'original.pdf';\r
$this->uncompressed = $this->out . 'uncompressed.pdf';\r
$this->infos = $this->out . 'infos.txt';\r
- $this->textes = $this->out . 'textes.txt';\r
- $this->phperrors = $this->out . 'php.err';\r
if (!file_exists($this->out)) {\r
mkdir($this->out, 0755, true);\r
}\r
$this->log_pointer = fopen($this->log, 'a');\r
- // $this->_memoErrorLog = ini_get('error_log');\r
- // ini_set('error_log', $this->phperrors);\r
}\r
\r
public function copyOriginal($tmp_file)\r
{\r
move_uploaded_file($tmp_file, $this->in);\r
- $this->uncompress();\r
+ //$this->uncompress();\r
}\r
\r
public function uncompress()\r
return $this->generalInfos['pages'];\r
}\r
\r
+ public function globalOperations()\r
+ {\r
+ $this->getLinks();\r
+ $this->getTexts();\r
+ }\r
+\r
public function processOnePage($page)\r
{\r
- $this->getTexts($page);\r
$this->makeMiniShot($page);\r
$this->makeRealShot($page);\r
$this->makeSWFFiles($page);\r
}\r
}\r
\r
- public function getTexts($page)\r
+ public function getTexts()\r
{\r
+ $temp = cubeFiles::tempnam();\r
$pdftotext = new cubeCommandLine('pdftotext', null, true);\r
$pdftotext->setPath(CONVERTER_PATH);\r
$pdftotext->setArg('q');\r
- $pdftotext->setArg('f', $page);\r
- $pdftotext->setArg('l', $page);\r
$pdftotext->setArg('-eol', 'unix');\r
$pdftotext->setArg('-enc', 'UTF-8');\r
$pdftotext->setArg(null, $this->in);\r
- $pdftotext->setArg(null, $this->out . 'p' . $page . '.txt');\r
+ $pdftotext->setArg(null, $temp);\r
$pdftotext->execute();\r
$this->addToLog($pdftotext);\r
+\r
+ $pages = preg_split("|\x{u000c}|", file_get_contents($temp));\r
+ foreach($pages as $i => $page) {\r
+ $i++;\r
+ file_put_contents($this->out . 'p' . $i . '.txt', cubeText::removeAccents($page));\r
+ }\r
+\r
+ unlink($temp);\r
}\r
\r
public function makeMiniShot($page)\r
}\r
}\r
\r
- public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0, &$muliply = 1)\r
+ public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0)\r
{\r
if ($maxObjects <= 1) {\r
$method = self::POLY2BITMAP;\r
}\r
\r
- $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, $multiply);\r
+ $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method);\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['outputfile'])) {\r
- $fp = fopen($out['outputfile'], 'rb');\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
if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {\r
$written = true;\r
}\r
- if ($written && $method < self::BITMAP && !isset($this->_links[$page])) {\r
- $this->_links[$page] = $this->extractLinks($page, $out['outputfile'], $out['multiply']);\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);\r
}\r
\r
if (!$written || $overflow || $overflowObjects) {\r
- return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1, $multiply);\r
+ $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1);\r
}\r
}\r
-\r
- return $out;\r
}\r
\r
protected function checkObjectsNumber($file, $maxObjects)\r
return false;\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)\r
{\r
/*\r
}\r
\r
if ($method < self::BARBARE_PNM) {\r
- $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
-\r
$pdf2swf = new cubeCommandLine('pdf2swf', null, true);\r
$pdf2swf->setPath(CONVERTER_PATH);\r
\r
} elseif ($method == self::POLY2BITMAP) {\r
// Raster graphics, keep texts\r
$pdf2swf->setArg('poly2bitmap');\r
- $multiply = $resolution2multiply[$resolution];\r
+ $multiply = self::$resolution2multiply[$resolution];\r
$pdf2swf->setArg('multiply', $multiply);\r
} elseif ($method == self::BITMAP) {\r
// Raster all\r
$pdf2swf->setArg('bitmap');\r
- $multiply = $resolution2multiply[$resolution];\r
+ $multiply = self::$resolution2multiply[$resolution];\r
$pdf2swf->setArg('multiply', $multiply);\r
}\r
\r
$pdf2swf->setArg('stop');\r
- $pdf2swf->setManualArg('-vvvv');\r
+ $pdf2swf->setManualArg('-v');\r
$pdf2swf->setArg('T', 8);\r
if ($storeAllChars) {\r
$pdf2swf->setArg('fonts');\r
$pdf2swf->execute();\r
\r
$this->addToLog($pdf2swf, true);\r
- return array('outputfile' => $pdf2swf->outputfile, 'multiply' => $multiply, 'object' => $pdf2swf);\r
} else {\r
- return array('outputfile' => $this->pdf2swfBarbare($page, $resolution, $quality, $method), 'multiply' => 1);\r
+ $this->pdf2swfBarbare($page, $resolution, $quality, $method);\r
}\r
}\r
\r
$this->addToLog($swfcombine);\r
}\r
\r
+ protected function getLinks()\r
+ {\r
+ $fwstk = new cubeCommandLine('fwstk', 'C:\Users\Vincent\Desktop\out.txt', false);\r
+ $fwstk->setPath(CONVERTER_PATH);\r
+ $fwstk->setArg('--input ' . $this->in);\r
+ $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');\r
+ $fwstk->execute();\r
+ $this->addToLog($fwstk);\r
+ }\r
+\r
protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4)\r
{\r
// Fabrique les images\r
fwrite($this->log_pointer, $c);\r
}\r
\r
- public function extractLinks($page, $outputfile, $multiply = 1)\r
- {\r
- /*\r
-DEBUG drawlink\r
-TRACE drawlink 122.00/579.00 236.00/579.00 236.00/527.00 122.00/527.00\r
-DEBUG | moveTo 122.00 579.00\r
-DEBUG | lineTo 236.00 579.00\r
-DEBUG | lineTo 236.00 527.00\r
-DEBUG | lineTo 122.00 527.00\r
-DEBUG | lineTo 122.00 579.00\r
-TRACE drawlink action=3\r
-TRACE drawlink s=http://www.ladocumentationfrancaise.fr/\r
-*/\r
-\r
- $fp = fopen($outputfile, 'rb');\r
- $log = 'BEGIN extracting link' . "\n";\r
- $link = null;\r
- while ($line = fgets($fp)) {\r
- $line = trim($line);\r
- if (preg_match('|TRACE drawlink(( [-0-9\./]+)+)|', $line, $matches)) {\r
- $log .= 'FOUND a link' . "\n";\r
- $link = new wsLink($multiply);\r
- $log .= 'SETTING POINTS ' . $matches[1] . "\n";\r
- $points = explode(' ', trim($matches[1]));\r
- foreach($points as $point) {\r
- $p = explode('/', $point);\r
- $log .= 'SET POINT ' . $p[0] . ' ' . $p[1] . "\n";\r
- $link->addPoint($p);\r
- }\r
- } elseif (preg_match('|TRACE drawlink action=(.*)|', $line, $matches)) {\r
- $log .= 'SETTING ACTION ' . $matches[1] . "\n";\r
- if (is_null($link)) {\r
- continue;\r
- }\r
- $link->setAction($matches[1]);\r
- } elseif (preg_match('|TRACE drawlink s=(.*)|', $line, $matches)) {\r
- $log .= 'SETTING LINK ' . $matches[1] . "\n";\r
- if (is_null($link)) {\r
- continue;\r
- }\r
- $link->setLink($matches[1]);\r
- $this->links[$page][] = $link->toArray();\r
- $log .= 'SAVE LINK' . print_r($link->toArray(), true) . "\n";\r
- $link = null;\r
- }\r
- }\r
- $log .= 'END OF EXTRACTING' . "\n";\r
- $this->addToLog($log);\r
- fclose($fp);\r
-\r
- return $log;\r
- }\r
-\r
public function __destruct()\r
{\r
if (isset($this->log_pointer) && is_resource($this->log_pointer)) {\r
fclose($this->log_pointer);\r
}\r
- // ini_set('error_log', $this->_memoErrorLog);\r
}\r
}\r
\r