]> _ Git - fluidbook_tools.git/commitdiff
wait #5844 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Apr 2023 09:20:12 +0000 (11:20 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Apr 2023 09:20:12 +0000 (11:20 +0200)
src/Compiler/Compiler.php
src/Compiler/CompilerInterface.php
src/Compiler/DummyCompiler.php
src/Compiler/FluidbookCompiler.php
src/Links/ArticlePDFLink.php [new file with mode: 0644]
src/Links/Link.php
src/Links/PDFPopupLink.php

index eaeb7461e87afe5f2c82e7ade4ee2024905f46b5..366b2cb78eee46d09caf1307e2f91341ee04ca07 100644 (file)
@@ -380,4 +380,16 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
     public function isOnePage(): bool {
         // TODO: Implement isOnePage() method.
     }
+
+    public function addPDFJS($force = false) {
+        // TODO: Implement addPDFJS() method.
+    }
+
+    public function addSEOArticle($page, $title, $intro, $image, $id = null, $url = null, $content = '') {
+        // TODO: Implement addSEOArticle() method.
+    }
+
+    public function pushSetting($key, $value) {
+        // TODO: Implement pushSetting() method.
+    }
 }
index 36a79f90a685ae345c9c4cf7da9f96840d988bd6..96e3f0b84142ee4e1daca84f7453ebc2d6ba0ceb 100644 (file)
@@ -51,4 +51,8 @@ interface CompilerInterface {
     public function simpleCopyLinkFile($source, $dest);
 
     public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false);
+
+    public function addPDFJS($force = false);
+
+    public function addSEOArticle($page, $title, $intro, $image, $id = null, $url = null, $content = '');
 }
index f5e15d614a26cb6a1c778a86645286a0b64a2860..393ffeeb60e7bfbb5a3bc94bae5865c119347c3a 100644 (file)
@@ -107,4 +107,12 @@ class DummyCompiler implements CompilerInterface {
     public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false) {
         // TODO: Implement unzipFile() method.
     }
+
+    public function addPDFJS($force = false) {
+        // TODO: Implement addPDFJS() method.
+    }
+
+    public function addSEOArticle($page, $title, $intro, $image, $id = null, $url = null, $content = '') {
+        // TODO: Implement addSEOArticle() method.
+    }
 }
index 7b6d28ce23b37e2019f6d43f52121a435e034f99..b4917aa9f26a2173300dbc9d032600fd134c91d3 100644 (file)
@@ -64,4 +64,5 @@ trait FluidbookCompiler
 
 
 
+
 }
diff --git a/src/Links/ArticlePDFLink.php b/src/Links/ArticlePDFLink.php
new file mode 100644 (file)
index 0000000..7d68949
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+namespace Fluidbook\Tools\Links;
+
+use Cubist\Util\Graphics\Image;
+
+class ArticlePDFLink extends ArticleLink {
+    public $title = '';
+    public $description = '';
+
+    public function init() {
+        $this->compiler->addPDFJS(true);
+
+        $e = explode('.', $this->to);
+        array_pop($e);
+        $name = implode('.', $e);
+        $pdffile = $this->compiler->getWorkingDir() . $this->to;
+        $mtime = filemtime($pdffile);
+
+        $htmlfile = $this->compiler->getWorkingDir() . $name . '.html';
+        if (!file_exists($htmlfile) || filemtime($htmlfile) < $mtime) {
+            $cmd = "pdftotext -f 1 -l 1 -htmlmeta $pdffile $htmlfile";
+            `$cmd`;
+        }
+
+        $cut = $this->wdir . $name . '.c.pdf';
+        $size = $this->wdir . $name . '.s.pdf';
+
+        $dim = Image::getimagesize($pdffile);
+        $infos = ['width' => $dim[0], 'height' => $dim[1]];
+        if (!file_exists($cut) || !file_exists($size) || filemtime($size) < $mtime) {
+            // Cut the pdf in many pages
+            $ratio = $infos['width'] / $infos['height'];
+            $nb = max(1, ceil(0.707071 / $ratio));
+
+            if ($nb == 1) {
+                copy($pdffile, $cut);
+            } else {
+                `mutool poster -y $nb $pdffile $cut`;
+            }
+
+            // Resize to 210mm width
+            `pdfposter $cut $size`;
+        } else {
+
+        }
+
+        $this->copyExternalFile($name . '.s.pdf');
+        $this->copyExternalFile($name . '.c.pdf');
+        $text = file_get_contents($htmlfile);
+        $this->article = ['page' => $this->page, 'type' => 'pdf', 'id' => $name, 'url' => $name, 'infos' => $infos, 'printcontent' => $name . '.s.pdf', 'content' => $name . '.c.pdf', 'textcontent' => $text];
+
+        $this->compiler->pushSetting('articlesList', $this->article);
+        $this->compiler->addSEOArticle('#/article/' . $name, $this->title, $this->description, '', $name, $name . '.html', $text);
+    }
+}
index 91bc09b3248ae1fc335d40f7b64f24563193904c..3ca77e14e44c3b7f25a5b440a8a01df270f68ec0 100644 (file)
@@ -204,7 +204,11 @@ class Link {
             case 35:
                 return new TextLink($id, $init, $compiler);
             case 36:
-                return new ArticleLink($id, $init, $compiler);
+                if (stripos($init['to'], '.pdf') !== false) {
+                    return new ArticlePDFLink($id, $init, $compiler);
+                } else {
+                    return new ArticleLink($id, $init, $compiler);
+                }
             case 37:
                 return new DownloadPortionLink($id, $init, $compiler);
             case 38:
index 4f03f02c48f942e68e1e7e80334679c7d872c2ca..9bb73c766c81f3d497c07b7e34fd97eb6c43f3a8 100644 (file)
@@ -2,13 +2,22 @@
 
 namespace Fluidbook\Tools\Links;
 
+use Cubist\Util\Graphics\Image;
+use Cubist\PDF\PDFTools;
+
 class PDFPopupLink extends NormalLink {
     public function getDefaultTooltip() {
         return 'click to open the document';
     }
 
+    /**
+     * @throws \Exception
+     */
     public function getURL() {
+        $this->compiler->addPDFJS(true);
+        $dim = PDFTools::getDimensions($this->compiler->getWorkingDir() . $this->to);
+        $this->compiler->config->set('pdfLinks.' . $this->uid, ['width' => $dim['size'][0], 'height' => $dim['size'][1], 'totalHeight' => $dim['totalHeight'], 'file' => $this->to, 'interface' => $this->pdfjs]);
         $this->copyExternalFile($this->to);
-        return '#/pdf/' . $this->to;
+        return '#/pdf/' . $this->uid;
     }
 }