]> BookStack Code Mirror - bookstack/commitdiff
Added wkhtmltopdf support and done some style tweaks
authorDan Brown <redacted>
Sun, 1 Jan 2017 12:20:30 +0000 (12:20 +0000)
committerDan Brown <redacted>
Sun, 1 Jan 2017 12:20:30 +0000 (12:20 +0000)
Closes #248

.gitignore
app/Services/ExportService.php
composer.json
composer.lock
config/app.php
config/snappy.php [new file with mode: 0644]
resources/assets/sass/_forms.scss
resources/views/pages/revisions.blade.php

index 362df57e13a1f29f4daf103ff8d5bf7e63267ace..83b754c04dd64c9ba813f6bacb933a1d3a58faec 100644 (file)
@@ -13,3 +13,4 @@ _ide_helper.php
 /storage/debugbar
 .phpstorm.meta.php
 yarn.lock
+/bin
\ No newline at end of file
index 14084d320628a7f29e851f5b7a68f1b9a4b810da..50ba75c17a93a22f7dc8b16d7820fed26338e24d 100644 (file)
@@ -1,6 +1,5 @@
 <?php namespace BookStack\Services;
 
-
 use BookStack\Page;
 
 class ExportService
@@ -28,8 +27,13 @@ class ExportService
     {
         $cssContent = file_get_contents(public_path('/css/export-styles.css'));
         $pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render();
+        $useWKHTML = config('snappy.pdf.binary') !== false;
         $containedHtml = $this->containHtml($pageHtml);
-        $pdf = \PDF::loadHTML($containedHtml);
+        if ($useWKHTML) {
+            $pdf = \SnappyPDF::loadHTML($containedHtml);
+        } else {
+            $pdf = \PDF::loadHTML($containedHtml);
+        }
         return $pdf->output();
     }
 
index 7d4b5e62b03a1132b39efe3d3f39fe9b2f47bf59..5a8fd67aea14d39ff03eee5bad2c599ea41837dc 100644 (file)
@@ -15,7 +15,8 @@
         "league/flysystem-aws-s3-v3": "^1.0",
         "barryvdh/laravel-dompdf": "^0.7",
         "predis/predis": "^1.1",
-        "gathercontent/htmldiff": "^0.2.1"
+        "gathercontent/htmldiff": "^0.2.1",
+        "barryvdh/laravel-snappy": "^0.3.1"
     },
     "require-dev": {
         "fzaninotto/faker": "~1.4",
index 74a0902882376a9d16fc1a8ac18f5398a0c1c33f..dcde9d9c69fca5265d4813e94878cdd604895e21 100644 (file)
@@ -4,8 +4,8 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "3124d900cfe857392a94de479f3ff6d4",
-    "content-hash": "a968767a73f77e66e865c276cf76eedf",
+    "hash": "2438a2f4a02adbea5f378f9e9408eb29",
+    "content-hash": "6add8bff71ecc86e0c90858590834a26",
     "packages": [
         {
             "name": "aws/aws-sdk-php",
             ],
             "time": "2016-07-04 11:52:48"
         },
+        {
+            "name": "barryvdh/laravel-snappy",
+            "version": "v0.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/barryvdh/laravel-snappy.git",
+                "reference": "509a4497be63d8ee7ff464a3daf00d9edde08e21"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/509a4497be63d8ee7ff464a3daf00d9edde08e21",
+                "reference": "509a4497be63d8ee7ff464a3daf00d9edde08e21",
+                "shasum": ""
+            },
+            "require": {
+                "illuminate/filesystem": "5.0.x|5.1.x|5.2.x|5.3.x",
+                "illuminate/support": "5.0.x|5.1.x|5.2.x|5.3.x",
+                "knplabs/knp-snappy": "*",
+                "php": ">=5.4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "0.3-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Barryvdh\\Snappy\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Barry vd. Heuvel",
+                    "email": "[email protected]"
+                }
+            ],
+            "description": "Snappy PDF/Image for Laravel 4",
+            "keywords": [
+                "image",
+                "laravel",
+                "pdf",
+                "snappy",
+                "wkhtmltoimage",
+                "wkhtmltopdf"
+            ],
+            "time": "2016-08-05 13:08:28"
+        },
         {
             "name": "barryvdh/reflection-docblock",
             "version": "v2.0.4",
             ],
             "time": "2015-12-05 17:17:57"
         },
+        {
+            "name": "knplabs/knp-snappy",
+            "version": "0.4.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/KnpLabs/snappy.git",
+                "reference": "44f7a9b37d5686fd7db4c1e9569a802a5d16923f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/44f7a9b37d5686fd7db4c1e9569a802a5d16923f",
+                "reference": "44f7a9b37d5686fd7db4c1e9569a802a5d16923f",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.3",
+                "symfony/process": "~2.3|~3.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.7"
+            },
+            "suggest": {
+                "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency",
+                "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency",
+                "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency",
+                "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency",
+                "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "0.5.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-0": {
+                    "Knp\\Snappy": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "KNPLabs Team",
+                    "homepage": "http://knplabs.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "http://github.com/KnpLabs/snappy/contributors"
+                }
+            ],
+            "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.",
+            "homepage": "http://github.com/KnpLabs/snappy",
+            "keywords": [
+                "knp",
+                "knplabs",
+                "pdf",
+                "snapshot",
+                "thumbnail",
+                "wkhtmltopdf"
+            ],
+            "time": "2015-11-17 13:16:27"
+        },
         {
             "name": "laravel/framework",
             "version": "v5.3.11",
index 786f005ac963f2bf2836c7038c7f534b7a3088c2..0c3e1e71c5360ebb63e58587fd0a7c9197ec296c 100644 (file)
@@ -148,6 +148,7 @@ return [
         Barryvdh\DomPDF\ServiceProvider::class,
         Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
         Barryvdh\Debugbar\ServiceProvider::class,
+        Barryvdh\Snappy\ServiceProvider::class,
 
 
         /*
@@ -218,6 +219,7 @@ return [
 
         'ImageTool' => Intervention\Image\Facades\Image::class,
         'PDF' => Barryvdh\DomPDF\Facade::class,
+        'SnappyPDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
         'Debugbar'  => Barryvdh\Debugbar\Facade::class,
 
         /**
diff --git a/config/snappy.php b/config/snappy.php
new file mode 100644 (file)
index 0000000..73f21fd
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+return [
+    'pdf' => [
+        'enabled' => true,
+        'binary'  => file_exists(base_path('wkhtmltopdf')) ? base_path('wkhtmltopdf') : env('WKHTMLTOPDF', false),
+        'timeout' => false,
+        'options' => [],
+        'env'     => [],
+    ],
+    'image' => [
+        'enabled' => false,
+        'binary'  => '/usr/local/bin/wkhtmltoimage',
+        'timeout' => false,
+        'options' => [],
+        'env'     => [],
+    ],
+];
index 62a7b400122cc37cdc1adef0251d5e10b5ebb39c..7e6b800d2dbe1575d83d9119475fd778b661e439 100644 (file)
@@ -33,7 +33,7 @@
   position: relative;
   z-index: 5;
   textarea {
-    font-family: 'Roboto Mono';
+    font-family: 'Roboto Mono', monospace;
     font-style: normal;
     font-weight: 400;
     padding: $-xs $-m;
@@ -55,6 +55,7 @@
     display: flex;
     flex-direction: column;
     border: 1px solid #DDD;
+    width: 50%;
   }
   .markdown-display {
     padding: 0 $-m 0;
@@ -68,7 +69,7 @@
 .editor-toolbar {
   width: 100%;
   padding: $-xs $-m;
-  font-family: 'Roboto Mono';
+  font-family: 'Roboto Mono', monospace;
   font-size: 11px;
   line-height: 1.6;
   border-bottom: 1px solid #DDD;
index 3549f5f05cea7914173c644b846f69a830350218..3b9812abdc6c31376f142c1e5ac95f71d9bbdd39 100644 (file)
@@ -45,7 +45,7 @@
                             @else
                                 <a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a>
                                 <span class="text-muted">&nbsp;|&nbsp;</span>
-                                <a href="{{ $revision->getUrl('restore') }}" target="_blank">{{ trans('entities.pages_revisions_restore') }}</a>
+                                <a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a>
                             @endif
                         </td>
                     </tr>