From 6d0eee18e21625d72de19ebbfdca66c9eef88a13 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 19 May 2021 17:17:53 +0000 Subject: [PATCH] wait #4473 @1.5 --- inc/ws/Metier/class.ws.document.php | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index ae37c2071..95256ee37 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -35,7 +35,7 @@ class wsDocument extends cubeMetier protected $in; protected $html; protected $mf; - protected $uncompressed; + protected $fixed; protected $log; protected $common_log_pointer; protected $pages_log_pointers; @@ -68,7 +68,7 @@ class wsDocument extends cubeMetier $this->html = $this->out . '/html/'; $this->mf = $this->out . '/mf/'; $this->in = $this->out . 'original.pdf'; - $this->uncompressed = $this->out . 'uncompressed.pdf'; + $this->fixed = $this->out . 'fixed.pdf'; $this->infos = $this->out . 'infos.txt'; if (!file_exists($this->out)) { mkdir($this->out, 0755, true); @@ -108,18 +108,40 @@ class wsDocument extends cubeMetier public function copyOriginalFromUpload($tmp_file) { move_uploaded_file($tmp_file, $this->in); + $this->fixPDF(); } public function copyOriginalFromFile($file) { copy($file, $this->in); + $this->fixPDF(); } - public function copyOriginalFromOlderVersion() + public function fixPDF() { - if (!file_exists($this->in)) { - // copy('https://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in); + if (file_exists($this->fixed)) { + unlink($this->fixed); } + + $pdftk = new cubeCommandLine('pdftk'); + $pdftk->setPath(CONVERTER_PATH); + $pdftk->setArg(null, $this->in); + $pdftk->setArg(null, 'output'); + $pdftk->setArg(null, $this->fixed); + $pdftk->execute(); + $this->addToLog($pdftk); + + if (!file_exists($this->fixed)) { + $pdftocairo = new cubeCommandLine('pdftocairo'); + $pdftocairo->setPath(CONVERTER_PATH); + $pdftocairo->setArg(null, '-pdf'); + $pdftocairo->setArg(null, $this->in); + $pdftocairo->setArg(null, $this->fixed); + $pdftocairo->execute(); + $this->addToLog($pdftocairo); + $this->lnCrop(); + } + } public function extractFonts() @@ -131,7 +153,7 @@ class wsDocument extends cubeMetier public function getInfos($in = null, $force = false) { if (is_null($in)) { - $in = $this->in; + $in = $this->fixed; } if (!$force && file_exists($this->infos)) { @@ -267,7 +289,7 @@ class wsDocument extends cubeMetier public function lnCrop() { $root = dirname($this->cropped); - `cd $root;ln -s original.pdf crop.pdf`; + `cd $root;ln -s fixed.pdf crop.pdf`; } public function parseInfos($data) @@ -490,7 +512,7 @@ class wsDocument extends cubeMetier { $fwstk = new cubeCommandLine('fwstk.sh'); $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->in); + $fwstk->setArg('--input ' . $this->fixed); $fwstk->setArg('--cut ' . $mode); $fwstk->setArg('--output ' . $this->cropped); $fwstk->execute(); @@ -501,7 +523,7 @@ class wsDocument extends cubeMetier { $fwstk = new cubeCommandLine('fwstk.sh'); $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->in); + $fwstk->setArg('--input ' . $this->fixed); $fwstk->setArg('--trim'); $fwstk->setArg('--output ' . $this->cropped); $fwstk->execute(); -- 2.39.5