Added wkhtmltopdf support and done some style tweaks
Closes #248
Showing
8 changed files
with
152 additions
and
8 deletions
| 1 | <?php namespace BookStack\Services; | 1 | <?php namespace BookStack\Services; |
| 2 | 2 | ||
| 3 | - | ||
| 4 | use BookStack\Page; | 3 | use BookStack\Page; |
| 5 | 4 | ||
| 6 | class ExportService | 5 | class ExportService |
| ... | @@ -28,8 +27,13 @@ class ExportService | ... | @@ -28,8 +27,13 @@ class ExportService |
| 28 | { | 27 | { |
| 29 | $cssContent = file_get_contents(public_path('/css/export-styles.css')); | 28 | $cssContent = file_get_contents(public_path('/css/export-styles.css')); |
| 30 | $pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render(); | 29 | $pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render(); |
| 30 | + $useWKHTML = config('snappy.pdf.binary') !== false; | ||
| 31 | $containedHtml = $this->containHtml($pageHtml); | 31 | $containedHtml = $this->containHtml($pageHtml); |
| 32 | - $pdf = \PDF::loadHTML($containedHtml); | 32 | + if ($useWKHTML) { |
| 33 | + $pdf = \SnappyPDF::loadHTML($containedHtml); | ||
| 34 | + } else { | ||
| 35 | + $pdf = \PDF::loadHTML($containedHtml); | ||
| 36 | + } | ||
| 33 | return $pdf->output(); | 37 | return $pdf->output(); |
| 34 | } | 38 | } |
| 35 | 39 | ... | ... |
| ... | @@ -15,7 +15,8 @@ | ... | @@ -15,7 +15,8 @@ |
| 15 | "league/flysystem-aws-s3-v3": "^1.0", | 15 | "league/flysystem-aws-s3-v3": "^1.0", |
| 16 | "barryvdh/laravel-dompdf": "^0.7", | 16 | "barryvdh/laravel-dompdf": "^0.7", |
| 17 | "predis/predis": "^1.1", | 17 | "predis/predis": "^1.1", |
| 18 | - "gathercontent/htmldiff": "^0.2.1" | 18 | + "gathercontent/htmldiff": "^0.2.1", |
| 19 | + "barryvdh/laravel-snappy": "^0.3.1" | ||
| 19 | }, | 20 | }, |
| 20 | "require-dev": { | 21 | "require-dev": { |
| 21 | "fzaninotto/faker": "~1.4", | 22 | "fzaninotto/faker": "~1.4", | ... | ... |
| ... | @@ -4,8 +4,8 @@ | ... | @@ -4,8 +4,8 @@ |
| 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
| 5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
| 6 | ], | 6 | ], |
| 7 | - "hash": "3124d900cfe857392a94de479f3ff6d4", | 7 | + "hash": "2438a2f4a02adbea5f378f9e9408eb29", |
| 8 | - "content-hash": "a968767a73f77e66e865c276cf76eedf", | 8 | + "content-hash": "6add8bff71ecc86e0c90858590834a26", |
| 9 | "packages": [ | 9 | "packages": [ |
| 10 | { | 10 | { |
| 11 | "name": "aws/aws-sdk-php", | 11 | "name": "aws/aws-sdk-php", |
| ... | @@ -256,6 +256,58 @@ | ... | @@ -256,6 +256,58 @@ |
| 256 | "time": "2016-07-04 11:52:48" | 256 | "time": "2016-07-04 11:52:48" |
| 257 | }, | 257 | }, |
| 258 | { | 258 | { |
| 259 | + "name": "barryvdh/laravel-snappy", | ||
| 260 | + "version": "v0.3.1", | ||
| 261 | + "source": { | ||
| 262 | + "type": "git", | ||
| 263 | + "url": "https://github.com/barryvdh/laravel-snappy.git", | ||
| 264 | + "reference": "509a4497be63d8ee7ff464a3daf00d9edde08e21" | ||
| 265 | + }, | ||
| 266 | + "dist": { | ||
| 267 | + "type": "zip", | ||
| 268 | + "url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/509a4497be63d8ee7ff464a3daf00d9edde08e21", | ||
| 269 | + "reference": "509a4497be63d8ee7ff464a3daf00d9edde08e21", | ||
| 270 | + "shasum": "" | ||
| 271 | + }, | ||
| 272 | + "require": { | ||
| 273 | + "illuminate/filesystem": "5.0.x|5.1.x|5.2.x|5.3.x", | ||
| 274 | + "illuminate/support": "5.0.x|5.1.x|5.2.x|5.3.x", | ||
| 275 | + "knplabs/knp-snappy": "*", | ||
| 276 | + "php": ">=5.4.0" | ||
| 277 | + }, | ||
| 278 | + "type": "library", | ||
| 279 | + "extra": { | ||
| 280 | + "branch-alias": { | ||
| 281 | + "dev-master": "0.3-dev" | ||
| 282 | + } | ||
| 283 | + }, | ||
| 284 | + "autoload": { | ||
| 285 | + "psr-4": { | ||
| 286 | + "Barryvdh\\Snappy\\": "src/" | ||
| 287 | + } | ||
| 288 | + }, | ||
| 289 | + "notification-url": "https://packagist.org/downloads/", | ||
| 290 | + "license": [ | ||
| 291 | + "MIT" | ||
| 292 | + ], | ||
| 293 | + "authors": [ | ||
| 294 | + { | ||
| 295 | + "name": "Barry vd. Heuvel", | ||
| 296 | + "email": "barryvdh@gmail.com" | ||
| 297 | + } | ||
| 298 | + ], | ||
| 299 | + "description": "Snappy PDF/Image for Laravel 4", | ||
| 300 | + "keywords": [ | ||
| 301 | + "image", | ||
| 302 | + "laravel", | ||
| 303 | + "pdf", | ||
| 304 | + "snappy", | ||
| 305 | + "wkhtmltoimage", | ||
| 306 | + "wkhtmltopdf" | ||
| 307 | + ], | ||
| 308 | + "time": "2016-08-05 13:08:28" | ||
| 309 | + }, | ||
| 310 | + { | ||
| 259 | "name": "barryvdh/reflection-docblock", | 311 | "name": "barryvdh/reflection-docblock", |
| 260 | "version": "v2.0.4", | 312 | "version": "v2.0.4", |
| 261 | "source": { | 313 | "source": { |
| ... | @@ -998,6 +1050,71 @@ | ... | @@ -998,6 +1050,71 @@ |
| 998 | "time": "2015-12-05 17:17:57" | 1050 | "time": "2015-12-05 17:17:57" |
| 999 | }, | 1051 | }, |
| 1000 | { | 1052 | { |
| 1053 | + "name": "knplabs/knp-snappy", | ||
| 1054 | + "version": "0.4.3", | ||
| 1055 | + "source": { | ||
| 1056 | + "type": "git", | ||
| 1057 | + "url": "https://github.com/KnpLabs/snappy.git", | ||
| 1058 | + "reference": "44f7a9b37d5686fd7db4c1e9569a802a5d16923f" | ||
| 1059 | + }, | ||
| 1060 | + "dist": { | ||
| 1061 | + "type": "zip", | ||
| 1062 | + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/44f7a9b37d5686fd7db4c1e9569a802a5d16923f", | ||
| 1063 | + "reference": "44f7a9b37d5686fd7db4c1e9569a802a5d16923f", | ||
| 1064 | + "shasum": "" | ||
| 1065 | + }, | ||
| 1066 | + "require": { | ||
| 1067 | + "php": ">=5.3.3", | ||
| 1068 | + "symfony/process": "~2.3|~3.0" | ||
| 1069 | + }, | ||
| 1070 | + "require-dev": { | ||
| 1071 | + "phpunit/phpunit": "~4.7" | ||
| 1072 | + }, | ||
| 1073 | + "suggest": { | ||
| 1074 | + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", | ||
| 1075 | + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", | ||
| 1076 | + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", | ||
| 1077 | + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", | ||
| 1078 | + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" | ||
| 1079 | + }, | ||
| 1080 | + "type": "library", | ||
| 1081 | + "extra": { | ||
| 1082 | + "branch-alias": { | ||
| 1083 | + "dev-master": "0.5.x-dev" | ||
| 1084 | + } | ||
| 1085 | + }, | ||
| 1086 | + "autoload": { | ||
| 1087 | + "psr-0": { | ||
| 1088 | + "Knp\\Snappy": "src/" | ||
| 1089 | + } | ||
| 1090 | + }, | ||
| 1091 | + "notification-url": "https://packagist.org/downloads/", | ||
| 1092 | + "license": [ | ||
| 1093 | + "MIT" | ||
| 1094 | + ], | ||
| 1095 | + "authors": [ | ||
| 1096 | + { | ||
| 1097 | + "name": "KNPLabs Team", | ||
| 1098 | + "homepage": "http://knplabs.com" | ||
| 1099 | + }, | ||
| 1100 | + { | ||
| 1101 | + "name": "Symfony Community", | ||
| 1102 | + "homepage": "http://github.com/KnpLabs/snappy/contributors" | ||
| 1103 | + } | ||
| 1104 | + ], | ||
| 1105 | + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", | ||
| 1106 | + "homepage": "http://github.com/KnpLabs/snappy", | ||
| 1107 | + "keywords": [ | ||
| 1108 | + "knp", | ||
| 1109 | + "knplabs", | ||
| 1110 | + "pdf", | ||
| 1111 | + "snapshot", | ||
| 1112 | + "thumbnail", | ||
| 1113 | + "wkhtmltopdf" | ||
| 1114 | + ], | ||
| 1115 | + "time": "2015-11-17 13:16:27" | ||
| 1116 | + }, | ||
| 1117 | + { | ||
| 1001 | "name": "laravel/framework", | 1118 | "name": "laravel/framework", |
| 1002 | "version": "v5.3.11", | 1119 | "version": "v5.3.11", |
| 1003 | "source": { | 1120 | "source": { | ... | ... |
| ... | @@ -148,6 +148,7 @@ return [ | ... | @@ -148,6 +148,7 @@ return [ |
| 148 | Barryvdh\DomPDF\ServiceProvider::class, | 148 | Barryvdh\DomPDF\ServiceProvider::class, |
| 149 | Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, | 149 | Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, |
| 150 | Barryvdh\Debugbar\ServiceProvider::class, | 150 | Barryvdh\Debugbar\ServiceProvider::class, |
| 151 | + Barryvdh\Snappy\ServiceProvider::class, | ||
| 151 | 152 | ||
| 152 | 153 | ||
| 153 | /* | 154 | /* |
| ... | @@ -218,6 +219,7 @@ return [ | ... | @@ -218,6 +219,7 @@ return [ |
| 218 | 219 | ||
| 219 | 'ImageTool' => Intervention\Image\Facades\Image::class, | 220 | 'ImageTool' => Intervention\Image\Facades\Image::class, |
| 220 | 'PDF' => Barryvdh\DomPDF\Facade::class, | 221 | 'PDF' => Barryvdh\DomPDF\Facade::class, |
| 222 | + 'SnappyPDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, | ||
| 221 | 'Debugbar' => Barryvdh\Debugbar\Facade::class, | 223 | 'Debugbar' => Barryvdh\Debugbar\Facade::class, |
| 222 | 224 | ||
| 223 | /** | 225 | /** | ... | ... |
config/snappy.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +return [ | ||
| 4 | + 'pdf' => [ | ||
| 5 | + 'enabled' => true, | ||
| 6 | + 'binary' => file_exists(base_path('wkhtmltopdf')) ? base_path('wkhtmltopdf') : env('WKHTMLTOPDF', false), | ||
| 7 | + 'timeout' => false, | ||
| 8 | + 'options' => [], | ||
| 9 | + 'env' => [], | ||
| 10 | + ], | ||
| 11 | + 'image' => [ | ||
| 12 | + 'enabled' => false, | ||
| 13 | + 'binary' => '/usr/local/bin/wkhtmltoimage', | ||
| 14 | + 'timeout' => false, | ||
| 15 | + 'options' => [], | ||
| 16 | + 'env' => [], | ||
| 17 | + ], | ||
| 18 | +]; |
| ... | @@ -33,7 +33,7 @@ | ... | @@ -33,7 +33,7 @@ |
| 33 | position: relative; | 33 | position: relative; |
| 34 | z-index: 5; | 34 | z-index: 5; |
| 35 | textarea { | 35 | textarea { |
| 36 | - font-family: 'Roboto Mono'; | 36 | + font-family: 'Roboto Mono', monospace; |
| 37 | font-style: normal; | 37 | font-style: normal; |
| 38 | font-weight: 400; | 38 | font-weight: 400; |
| 39 | padding: $-xs $-m; | 39 | padding: $-xs $-m; |
| ... | @@ -55,6 +55,7 @@ | ... | @@ -55,6 +55,7 @@ |
| 55 | display: flex; | 55 | display: flex; |
| 56 | flex-direction: column; | 56 | flex-direction: column; |
| 57 | border: 1px solid #DDD; | 57 | border: 1px solid #DDD; |
| 58 | + width: 50%; | ||
| 58 | } | 59 | } |
| 59 | .markdown-display { | 60 | .markdown-display { |
| 60 | padding: 0 $-m 0; | 61 | padding: 0 $-m 0; |
| ... | @@ -68,7 +69,7 @@ | ... | @@ -68,7 +69,7 @@ |
| 68 | .editor-toolbar { | 69 | .editor-toolbar { |
| 69 | width: 100%; | 70 | width: 100%; |
| 70 | padding: $-xs $-m; | 71 | padding: $-xs $-m; |
| 71 | - font-family: 'Roboto Mono'; | 72 | + font-family: 'Roboto Mono', monospace; |
| 72 | font-size: 11px; | 73 | font-size: 11px; |
| 73 | line-height: 1.6; | 74 | line-height: 1.6; |
| 74 | border-bottom: 1px solid #DDD; | 75 | border-bottom: 1px solid #DDD; | ... | ... |
| ... | @@ -45,7 +45,7 @@ | ... | @@ -45,7 +45,7 @@ |
| 45 | @else | 45 | @else |
| 46 | <a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a> | 46 | <a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a> |
| 47 | <span class="text-muted"> | </span> | 47 | <span class="text-muted"> | </span> |
| 48 | - <a href="{{ $revision->getUrl('restore') }}" target="_blank">{{ trans('entities.pages_revisions_restore') }}</a> | 48 | + <a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a> |
| 49 | @endif | 49 | @endif |
| 50 | </td> | 50 | </td> |
| 51 | </tr> | 51 | </tr> | ... | ... |
-
Please register or sign in to post a comment