Added wkhtmltopdf support and done some style tweaks

Closes #248
This commit is contained in:
Dan Brown 2017-01-01 12:20:30 +00:00
parent 0eb90cb3b6
commit 3f0ef57d31
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
8 changed files with 152 additions and 8 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ _ide_helper.php
/storage/debugbar /storage/debugbar
.phpstorm.meta.php .phpstorm.meta.php
yarn.lock yarn.lock
/bin

View File

@ -1,6 +1,5 @@
<?php namespace BookStack\Services; <?php namespace BookStack\Services;
use BookStack\Page; use BookStack\Page;
class ExportService class ExportService
@ -28,8 +27,13 @@ class ExportService
{ {
$cssContent = file_get_contents(public_path('/css/export-styles.css')); $cssContent = file_get_contents(public_path('/css/export-styles.css'));
$pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render(); $pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render();
$useWKHTML = config('snappy.pdf.binary') !== false;
$containedHtml = $this->containHtml($pageHtml); $containedHtml = $this->containHtml($pageHtml);
if ($useWKHTML) {
$pdf = \SnappyPDF::loadHTML($containedHtml);
} else {
$pdf = \PDF::loadHTML($containedHtml); $pdf = \PDF::loadHTML($containedHtml);
}
return $pdf->output(); return $pdf->output();
} }

View File

@ -15,7 +15,8 @@
"league/flysystem-aws-s3-v3": "^1.0", "league/flysystem-aws-s3-v3": "^1.0",
"barryvdh/laravel-dompdf": "^0.7", "barryvdh/laravel-dompdf": "^0.7",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"gathercontent/htmldiff": "^0.2.1" "gathercontent/htmldiff": "^0.2.1",
"barryvdh/laravel-snappy": "^0.3.1"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",

121
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "3124d900cfe857392a94de479f3ff6d4", "hash": "2438a2f4a02adbea5f378f9e9408eb29",
"content-hash": "a968767a73f77e66e865c276cf76eedf", "content-hash": "6add8bff71ecc86e0c90858590834a26",
"packages": [ "packages": [
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
@ -255,6 +255,58 @@
], ],
"time": "2016-07-04 11:52:48" "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": "barryvdh@gmail.com"
}
],
"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", "name": "barryvdh/reflection-docblock",
"version": "v2.0.4", "version": "v2.0.4",
@ -997,6 +1049,71 @@
], ],
"time": "2015-12-05 17:17:57" "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", "name": "laravel/framework",
"version": "v5.3.11", "version": "v5.3.11",

View File

@ -148,6 +148,7 @@ return [
Barryvdh\DomPDF\ServiceProvider::class, Barryvdh\DomPDF\ServiceProvider::class,
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
Barryvdh\Debugbar\ServiceProvider::class, Barryvdh\Debugbar\ServiceProvider::class,
Barryvdh\Snappy\ServiceProvider::class,
/* /*
@ -218,6 +219,7 @@ return [
'ImageTool' => Intervention\Image\Facades\Image::class, 'ImageTool' => Intervention\Image\Facades\Image::class,
'PDF' => Barryvdh\DomPDF\Facade::class, 'PDF' => Barryvdh\DomPDF\Facade::class,
'SnappyPDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'Debugbar' => Barryvdh\Debugbar\Facade::class, 'Debugbar' => Barryvdh\Debugbar\Facade::class,
/** /**

18
config/snappy.php Normal file
View File

@ -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' => [],
],
];

View File

@ -33,7 +33,7 @@
position: relative; position: relative;
z-index: 5; z-index: 5;
textarea { textarea {
font-family: 'Roboto Mono'; font-family: 'Roboto Mono', monospace;
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
padding: $-xs $-m; padding: $-xs $-m;
@ -55,6 +55,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
border: 1px solid #DDD; border: 1px solid #DDD;
width: 50%;
} }
.markdown-display { .markdown-display {
padding: 0 $-m 0; padding: 0 $-m 0;
@ -68,7 +69,7 @@
.editor-toolbar { .editor-toolbar {
width: 100%; width: 100%;
padding: $-xs $-m; padding: $-xs $-m;
font-family: 'Roboto Mono'; font-family: 'Roboto Mono', monospace;
font-size: 11px; font-size: 11px;
line-height: 1.6; line-height: 1.6;
border-bottom: 1px solid #DDD; border-bottom: 1px solid #DDD;

View File

@ -45,7 +45,7 @@
@else @else
<a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a> <a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a>
<span class="text-muted">&nbsp;|&nbsp;</span> <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 @endif
</td> </td>
</tr> </tr>