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

index 241dbb92cfe5cad4b815b7043b3acb9dc129fd99..c5d8e07589d9aa94b00cfbcd5f779ea416e8d8cd 100644 (file)
@@ -65,7 +65,7 @@
       <path value="$PROJECT_DIR$/vendor/cubist/net" />
     </include_path>
   </component>
-  <component name="PhpProjectSharedConfiguration" php_language_level="8.0">
+  <component name="PhpProjectSharedConfiguration" php_language_level="7.3">
     <option name="suggestChangeDefaultLanguageLevel" value="false" />
   </component>
 </project>
\ No newline at end of file
index 9bf4bb21def600041d129fd29e497635c3ae3260..02f590ac601ebd0acb3165ed233569e55739d82a 100644 (file)
@@ -370,4 +370,52 @@ class PDFTools
 
     }
 
+    public static function split($pdf, $out)
+    {
+
+        $lock = $pdf . '.split.lock';
+        $returnAfterSleep = false;
+
+        usleep(rand(100000, 2000000));
+
+        while (file_exists($lock)) {
+            $returnAfterSleep = true;
+            sleep(5);
+        }
+        if ($returnAfterSleep) {
+            return;
+        }
+
+        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);
+                }
+            }
+        }
+        unlink($lock);
+    }
+
 }