protected $bookmarks;\r
protected $numberSections;\r
protected $links;\r
+ protected $crop;\r
\r
protected $out;\r
protected $in;\r
protected $log;\r
protected $log_pointer;\r
protected $infos;\r
+ protected $cropped;\r
+ protected $uncropped;\r
\r
private $_basicInfos = null;\r
private $_advancedInfos = null;\r
if (!file_exists($this->out)) {\r
mkdir($this->out, 0755, true);\r
}\r
+ $this->cropped = $this->out . 'crop.pdf';\r
+ $this->uncropped = $this->out . 'uncrop.pdf';\r
$this->log_pointer = fopen($this->log, 'a');\r
}\r
\r
public function copyOriginal($tmp_file)\r
{\r
move_uploaded_file($tmp_file, $this->in);\r
- //$this->uncompress();\r
- }\r
-\r
- public function uncompress()\r
- {\r
- $pdftk = new cubeCommandLine('pdftk');\r
- $pdftk->setPath(CONVERTER_PATH);\r
- $pdftk->setManualArg($this->in . ' output ' . $this->uncompressed . ' uncompress ');\r
- $pdftk->execute();\r
- $this->addToLog($pdftk);\r
+ $this->uncropDocument();\r
}\r
\r
public function getInfos()\r
$this->parseInfos($pdfinfo . $pdftk);\r
\r
file_put_contents($this->infos, $pdfinfo . $pdftk);\r
+ $this->crop = $this->findCutDisposition();\r
+ }\r
+\r
+ public function findCutDisposition()\r
+ {\r
+ $spreads = $this->detectSpreads();\r
+ if ($spreads) {\r
+ return $spreads;\r
+ }\r
+ return $this->detectPageDifferences();\r
+ }\r
+\r
+ protected function detectPageDifferences()\r
+ {\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 ($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
+ return 'TTRIM';\r
+ } else {\r
+ return 'TMANUEL';\r
+ }\r
+ }\r
+\r
+ protected function detectSpreads()\r
+ {\r
+ $spread = false;\r
+ // Détection des spreads\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
+ if ($ratio <= 1) {\r
+ return false;\r
+ } elseif ($ratio >= 6) {\r
+ return 'CSL8';\r
+ } elseif ($ratio >= 3) {\r
+ return 'CSL4';\r
+ } elseif ($ratio >= 2) {\r
+ return 'CSL3';\r
+ } else {\r
+ return 'CS-14-23';\r
+ }\r
+ }\r
+\r
+ if ($first == $last && round($first[0] * 2) == round($second[0])) {\r
+ return 'C1-23-4';\r
+ }\r
+ if (round($first[0] * 2) == round($second[0]) && $last == $second) {\r
+ return 'C1-23';\r
+ }\r
}\r
\r
public function getBasicInfos()\r
if ($k == 'Pages' || $k == 'NumberOfPages') {\r
$this->pages = $this->generalInfos['pages'] = $v;\r
} elseif (preg_match('|Page ([0-9]+) (.*)Box: ([0-9.]*) ([0-9.]*) ([0-9.]*) ([0-9.]*)|iu', $line, $m)) {\r
- $this->generalInfos['page'][$m[1]][strtolower($m[2])] = array($m[3], $m[4], $m[5], $m[6]);\r
+ $this->generalInfos['page'][$m[1]][strtolower($m[2])] = new wsBox($m[3], $m[4], $m[5], $m[6]);\r
} elseif (preg_match('|Page ([0-9]+) size: ([0-9.]*)([\sx]+)([0-9.]*)(.*)|iu', $line, $m)) {\r
$this->generalInfos['page'][$m[1]]['size'] = array($m[2], $m[4]);\r
$this->generalInfos['size'][0] = max($this->generalInfos['size'][0], $m[2]);\r
$this->numberSections[] = $section;\r
}\r
}\r
+\r
return $res;\r
}\r
\r
\r
public function globalOperations()\r
{\r
+ $this->getInfos();\r
+ $this->Crop();\r
$this->getLinks();\r
$this->getTexts();\r
}\r
\r
+ public function Crop()\r
+ {\r
+ if ($this->crop == 'TTRIM') {\r
+ $this->trimDocument();\r
+ } else {\r
+ copy($this->in, $this->cropped);\r
+ }\r
+ }\r
+\r
+ public function trimDocument()\r
+ {\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 uncropDocument()\r
+ {\r
+ $fwstk = new cubeCommandLine('fwstk');\r
+ $fwstk->setPath(CONVERTER_PATH);\r
+ $fwstk->setArg('--input ' . $this->in);\r
+ $fwstk->setArg('--reset');\r
+ $fwstk->setArg('--output ' . $this->uncropped);\r
+ $fwstk->execute();\r
+ $this->addToLog($fwstk);\r
+ }\r
+\r
public function processOnePage($page)\r
{\r
$this->makeMiniShot($page);\r
$this->makeRealShot($page);\r
- $this->makeSWFFiles($page);\r
+ $this->makeSWFFiles($page, 150, 90, true, 1800, 1);\r
$this->makeAS3($page);\r
}\r
\r
$pdftotext->setArg('q');\r
$pdftotext->setArg('-eol', 'unix');\r
$pdftotext->setArg('-enc', 'UTF-8');\r
- $pdftotext->setArg(null, $this->in);\r
+ $pdftotext->setArg(null, $this->cropped);\r
$pdftotext->setArg(null, $temp);\r
$pdftotext->execute();\r
$this->addToLog($pdftotext);\r
\r
- $pages = preg_split("|\x{u000c}|", file_get_contents($temp));\r
+ $pages = explode("\f", 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
+ $txt = mb_strtolower($page);\r
+ $txt = cubeText::removeAccents($txt);\r
+ $txt = trim($txt);\r
+\r
+ file_put_contents($this->out . 'p' . $i . '.txt', $txt);\r
}\r
\r
unlink($temp);\r
\r
public function makeMiniShot($page)\r
{\r
- $this->makeShotFixedWidth($page, 'p', 100, 70, 4, 'GS');\r
+ $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'GS');\r
}\r
\r
public function makeRealShot($page)\r
{\r
- $this->makeShot($page, 'te', 72);\r
+ $this->makeShot($page, 'te', 150, 60, 4, 'GS', $this->uncropped);\r
}\r
\r
public function makeShotFixedWidth($page , $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'GS')\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 = 'GS')\r
+ public function makeShot($page , $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS', $in = null)\r
{\r
+ if (is_null($in)) {\r
+ $in = $this->cropped;\r
+ }\r
// Delete all old files\r
if ($method == 'GS') {\r
- $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing);\r
+ $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
} elseif ($method == 'PNM') {\r
- $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing);\r
+ $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
}\r
// Test the result by checking all files\r
if (!file_exists($this->out . $prefix . $page . '.jpg')) {\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);\r
+ $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
} elseif ($method == 'PNM') {\r
- $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing);\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)\r
+ protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)\r
{\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->setArg('-dNOPAUSE');\r
$gs->setArg('-dNOPROMPT');\r
$gs->setArg('-sDEVICE=jpeg');\r
+ // Dispotion & colors\r
$gs->setArg('-dUseCIEColor');\r
+ $gs->setArg('-dAutoRotatePages=/None');\r
+ // Resolution & Quality\r
$gs->setArg('-r' . $resolution);\r
$gs->setArg('-dJPEGQ=' . $quality);\r
+ // Antialias\r
+ $gs->setArg('-dDOINTERPOLATE');\r
$gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
$gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
- // $gs->setArg('-dUseCropBox');\r
+ // Performances\r
+ $gs->setArg('-dNumRenderingThreads=4');\r
+ // Page range\r
$gs->setArg('-dFirstPage=' . $page);\r
$gs->setArg('-dLastPage=' . $page);\r
- $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . '%d.jpg');\r
- $gs->setArg('-dAutoRotatePages=/None');\r
- $gs->setArg(null, $this->in);\r
+ // Files\r
+ $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . $page . '.jpg');\r
+\r
+ $gs->setArg(null, $in);\r
$gs->execute();\r
$this->addToLog($gs);\r
}\r
\r
- protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4)\r
+ protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)\r
{\r
+ if (is_null($in)) {\r
+ $in = $this->crop;\r
+ }\r
$antialiasing = $antialiasing?'yes':'no';\r
$resolution = round($resolution);\r
// Exporte les fichiers\r
$pdftoppm->setArg('-t1lib yes');\r
}\r
$pdftoppm->setArg('r', $resolution);\r
- $pdftoppm->setArg(null, $this->in);\r
+ $pdftoppm->setArg(null, $in);\r
$pdftoppm->setArg(null, $this->out . 'ppm');\r
$pdftoppm->execute();\r
$this->addToLog($pdftoppm);\r
if ($maxObjects <= 1) {\r
$method = self::POLY2BITMAP;\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->crop) {\r
+ $method = max($method, self::FLATTEN);\r
+ }\r
\r
$out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method);\r
if ($method < self::BARBARE_PNM) {\r
}\r
\r
$pdf2swf->setArg('stop');\r
- $pdf2swf->setManualArg('-v');\r
+ // $pdf2swf->setManualArg('-v');\r
$pdf2swf->setArg('T', 8);\r
if ($storeAllChars) {\r
$pdf2swf->setArg('fonts');\r
$pdf2swf->setArg('set disablelinks');\r
$pdf2swf->setArg('set dots');\r
\r
- $pdf2swf->setArg(null, $this->in);\r
+ $pdf2swf->setArg(null, $this->cropped);\r
$pdf2swf->setArg('output', $this->out . 'p%.swf');\r
$pdf2swf->execute();\r
\r
$swfcombine->setArg('merge');\r
$swfcombine->setArg('stack1');\r
$swfcombine->setArg('z');\r
- $swfcombine->setManualArg('-vvvv');\r
+ $swfcombine->setManualArg('-v');\r
$swfcombine->setArg('o', $swffile);\r
$swfcombine->setArg(null, ROOT . '/swf/as3Container.swf');\r
$swfcombine->setManualArg('content=' . $swffile);\r
\r
protected function getLinks()\r
{\r
- $fwstk = new cubeCommandLine('fwstk', 'C:\Users\Vincent\Desktop\out.txt', false);\r
+ $fwstk = new cubeCommandLine('fwstk');\r
$fwstk->setPath(CONVERTER_PATH);\r
$fwstk->setArg('--input ' . $this->in);\r
$fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');\r