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.
+ }
}
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 = '');
}
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.
+ }
}
--- /dev/null
+<?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);
+ }
+}
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:
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;
}
}