]> _ Git - fluidbook_tools.git/commitdiff
wip #5220
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 May 2022 15:41:12 +0000 (17:41 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 May 2022 15:41:12 +0000 (17:41 +0200)
src/Jobs/ProcessPage.php

index f64edf57d608e720b53317067df4243a56a5f8c0..6e11ae9d27a5945269d1444fd64b8b41c9539a48 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Fluidbook\Tools\Jobs;
 
+use Cubist\PDF\PDFTools;
 use Cubist\Util\Files\Files;
 use Fluidbook\Tools\Document;
 use Illuminate\Bus\Queueable;
@@ -34,19 +35,19 @@ class ProcessPage implements ShouldQueue
     /**
      * @var bool
      */
-    protected $debug=true;
+    protected $debug = true;
 
     /**
      * @param $document Document
      * @param $page integer
      * @param ProcessFile[] $files
      */
-    public function __construct($document, $page, $files = [],$debug=true)
+    public function __construct($document, $page, $files = [], $debug = true)
     {
         $this->document = $document;
         $this->page = $page;
         $this->files = $files;
-        $this->debug=$debug;
+        $this->debug = $debug;
     }
 
     /**
@@ -75,13 +76,13 @@ class ProcessPage implements ShouldQueue
 
     public function handle()
     {
-        if($this->debug) {
+        if ($this->debug) {
             start_measure('Process page ' . $this->page);
         }
         foreach ($this->files as $file) {
             $this->getFile($this->page, $file, false);
         }
-        if($this->debug) {
+        if ($this->debug) {
             stop_measure('Process page ' . $this->page);
         }
     }
@@ -112,50 +113,11 @@ class ProcessPage implements ShouldQueue
 
     public function splitDoc()
     {
-        $lock = $this->getPDFInput() . '.split.lock';
-        $returnAfterSleep = false;
-
-        usleep(rand(100000, 2000000));
-
-        while (file_exists($lock)) {
-            $returnAfterSleep = true;
-            sleep(5);
-        }
-        if ($returnAfterSleep) {
-            return;
-        }
-
-        if($this->debug) {
+        if ($this->debug) {
             start_measure('Split PDF');
         }
-        touch($lock);
-
-        Files::mkdir($this->getOut() . '/pdf');
-        $pdftk = new CommandLine('pdftk');
-        $pdftk->setArg(null, $this->getPDFInput());
-        $pdftk->setArg(null, 'burst');
-        $pdftk->setArg(null, 'uncompress');
-        $pdftk->setArg(null, 'output');
-        $pdftk->setArg(null, $this->getOut() . 'pdf/p%d.pdf');
-        $pdftk->execute();
-
-
-        for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
-            // Remove annotations : https://gist.github.com/stefanschmidt/5248592
-            $file = sprintf($this->getOut() . 'pdf/p%d.pdf', $i);
-            $to = sprintf($this->getOut() . 'pdf/s%d.pdf', $i);
-            `LANG=C LC_CTYPE=C sed -n '/^\/Annots/!p' $file > $to`;
-            if (file_exists($to)) {
-                if (filesize($to) > 0) {
-                    unlink($file);
-                    rename($to, $file);
-                } else {
-                    unlink($to);
-                }
-            }
-        }
-        unlink($lock);
-        if($this->debug) {
+        PDFTools::split($this->getPDFInput(), $this->getOut() . '/pdf');
+        if ($this->debug) {
             stop_measure('Split PDF');
         }
     }