From: vincent@cubedesigners.com Date: Mon, 21 Feb 2011 18:25:23 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c40016b6dfb53cf47c48f8d50e75f73c0a111de9;p=cubeextranet.git --- diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 4b84a33f4..8b521b9df 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -110,8 +110,72 @@ class wsServices extends cubeFlashGateway { exit; } - public function getPDF() + public function exportpdf() { + global $core; + + $daoBook = new wsDAOBook($core->con); + $book = $daoBook->selectById($this->args['id']); + + if (is_null($book)) { + return; + } + + if (!$book->parametres->pdfComplex || !$book->parametres->pdf) { + return; + } + // Normalize range + $range = cubeArray::parseRange($this->args['range']); + if ($k = array_search(0, $range)) { + $range[$k] = 1; + } + if ($k = array_search($book->parametres->pages + 1, $range)) { + $range[$k] = $r->pages; + } + + if (!count($range)) { + return; + } + // Paths init + $baseDocument = WS_BOOKS . '/final/' . $book->book_id . '/data/document.pdf'; + if (!file_exists($baseDocument)) { + return; + } + $destDir = WS_CACHE . '/exportpdf/' . $book->book_id; + if (!file_exists($destDir)) { + mkdir($destDir, 0777, true); + } + $fname = md5(implode(',%ù', $range)) . '.pdf'; + $destFile = $destDir . '/' . $fname ; + $destURL = '/fluidbook/cache/exportpdf/' . $book->book_id . '/' . $fname; + // If result exists, don't make the pdf again + if (file_exists($destFile) && filemtime($destFile) > filemtime($baseDocument)) { + http::redirect($destURL); + exit; + } + // Prepare the command line + $l = array('A=' . $baseDocument, 'cat'); + foreach($range as $page) { + if ($page < 1 || $page > $book->parametres->pages) { + continue; + } + $l[] = 'A' . $page; + } + $l[] = 'output'; + $l[] = $destFile ; + + $args = implode(' ', $l); + // Execute the command line + $pdftk = new cubeCommandLine('pdftk'); + $pdftk->setPath(CONVERTER_PATH); + $pdftk->setManualArg($args); + $pdftk->execute(); + // Debug + fb($pdftk->command); + fb($pdftk->output); + // Return the url of the resulting pdf + http::redirect($destURL); + exit; } }