From 42b0cc5eb306f6548e4ccb80419edcb02e701381 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 17 May 2022 17:41:12 +0200 Subject: [PATCH] wip #5220 --- src/Jobs/ProcessPage.php | 56 +++++++--------------------------------- 1 file changed, 9 insertions(+), 47 deletions(-) diff --git a/src/Jobs/ProcessPage.php b/src/Jobs/ProcessPage.php index f64edf5..6e11ae9 100644 --- a/src/Jobs/ProcessPage.php +++ b/src/Jobs/ProcessPage.php @@ -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'); } } -- 2.39.5