]> _ Git - cubist_pdf.git/commitdiff
wip #5220
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 May 2022 15:54:44 +0000 (17:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 May 2022 15:54:44 +0000 (17:54 +0200)
src/PDFTools.php

index 02f590ac601ebd0acb3165ed233569e55739d82a..c85665c0bc502236f76abc0b047286538ccd0716 100644 (file)
@@ -374,6 +374,8 @@ class PDFTools
     {
 
         $lock = $pdf . '.split.lock';
+
+
         $returnAfterSleep = false;
 
         usleep(rand(100000, 2000000));
@@ -388,32 +390,36 @@ class PDFTools
 
         touch($lock);
 
-        Files::mkdir($out);
-        $pdftk = new CommandLine('pdftk');
-        $pdftk->setArg(null, $pdf);
-        $pdftk->setArg(null, 'burst');
-        $pdftk->setArg(null, 'uncompress');
-        $pdftk->setArg(null, 'output');
-        $pdftk->setArg(null, $out . '/p%d.pdf');
-        $pdftk->execute();
-
-
-        for ($i = 1; true; $i++) {
-            // Remove annotations : https://gist.github.com/stefanschmidt/5248592
-            $file = sprintf($out . '/p%d.pdf', $i);
-            if (!file_exists($file)) {
-                break;
-            }
-            $to = sprintf($out . '/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);
+        try {
+            Files::mkdir($out);
+            $pdftk = new CommandLine('pdftk');
+            $pdftk->setArg(null, $pdf);
+            $pdftk->setArg(null, 'burst');
+            $pdftk->setArg(null, 'uncompress');
+            $pdftk->setArg(null, 'output');
+            $pdftk->setArg(null, $out . '/p%d.pdf');
+            $pdftk->execute();
+
+
+            for ($i = 1; true; $i++) {
+                // Remove annotations : https://gist.github.com/stefanschmidt/5248592
+                $file = sprintf($out . '/p%d.pdf', $i);
+                if (!file_exists($file)) {
+                    break;
+                }
+                $to = sprintf($out . '/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);
+                    }
                 }
             }
+        } catch (\Exception $e) {
+
         }
         unlink($lock);
     }