exit;\r
}\r
\r
- public function getPDF()\r
+ public function exportpdf()\r
{\r
+ global $core;\r
+\r
+ $daoBook = new wsDAOBook($core->con);\r
+ $book = $daoBook->selectById($this->args['id']);\r
+\r
+ if (is_null($book)) {\r
+ return;\r
+ }\r
+\r
+ if (!$book->parametres->pdfComplex || !$book->parametres->pdf) {\r
+ return;\r
+ }\r
+ // Normalize range\r
+ $range = cubeArray::parseRange($this->args['range']);\r
+ if ($k = array_search(0, $range)) {\r
+ $range[$k] = 1;\r
+ }\r
+ if ($k = array_search($book->parametres->pages + 1, $range)) {\r
+ $range[$k] = $r->pages;\r
+ }\r
+\r
+ if (!count($range)) {\r
+ return;\r
+ }\r
+ // Paths init\r
+ $baseDocument = WS_BOOKS . '/final/' . $book->book_id . '/data/document.pdf';\r
+ if (!file_exists($baseDocument)) {\r
+ return;\r
+ }\r
+ $destDir = WS_CACHE . '/exportpdf/' . $book->book_id;\r
+ if (!file_exists($destDir)) {\r
+ mkdir($destDir, 0777, true);\r
+ }\r
+ $fname = md5(implode(',%รน', $range)) . '.pdf';\r
+ $destFile = $destDir . '/' . $fname ;\r
+ $destURL = '/fluidbook/cache/exportpdf/' . $book->book_id . '/' . $fname;\r
+ // If result exists, don't make the pdf again\r
+ if (file_exists($destFile) && filemtime($destFile) > filemtime($baseDocument)) {\r
+ http::redirect($destURL);\r
+ exit;\r
+ }\r
+ // Prepare the command line\r
+ $l = array('A=' . $baseDocument, 'cat');\r
+ foreach($range as $page) {\r
+ if ($page < 1 || $page > $book->parametres->pages) {\r
+ continue;\r
+ }\r
+ $l[] = 'A' . $page;\r
+ }\r
+ $l[] = 'output';\r
+ $l[] = $destFile ;\r
+\r
+ $args = implode(' ', $l);\r
+ // Execute the command line\r
+ $pdftk = new cubeCommandLine('pdftk');\r
+ $pdftk->setPath(CONVERTER_PATH);\r
+ $pdftk->setManualArg($args);\r
+ $pdftk->execute();\r
+ // Debug\r
+ fb($pdftk->command);\r
+ fb($pdftk->output);\r
+ // Return the url of the resulting pdf\r
+ http::redirect($destURL);\r
+ exit;\r
}\r
}\r
\r