]> _ Git - cubeextranet.git/commitdiff
wait #4473 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 19 May 2021 17:17:53 +0000 (17:17 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 19 May 2021 17:17:53 +0000 (17:17 +0000)
inc/ws/Metier/class.ws.document.php

index ae37c2071d988bdf7a500c453a7ec2fc5e6fbef9..95256ee370e070cc63858d61ae110f9e85a4235a 100644 (file)
@@ -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();