Skip to content

Commit

Permalink
Added wkhtmltopdf support and done some style tweaks
Browse files Browse the repository at this point in the history
Closes #248
  • Loading branch information
ssddanbrown committed Jan 1, 2017
1 parent 0eb90cb commit 3f0ef57
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ _ide_helper.php
/storage/debugbar
.phpstorm.meta.php
yarn.lock
/bin
8 changes: 6 additions & 2 deletions app/Services/ExportService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack\Services;


use BookStack\Page;

class ExportService
Expand Down Expand Up @@ -28,8 +27,13 @@ public function pageToPdf(Page $page)
{
$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();
}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
121 changes: 119 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
Barryvdh\DomPDF\ServiceProvider::class,
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
Barryvdh\Debugbar\ServiceProvider::class,
Barryvdh\Snappy\ServiceProvider::class,


/*
Expand Down Expand Up @@ -218,6 +219,7 @@

'ImageTool' => Intervention\Image\Facades\Image::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
'SnappyPDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'Debugbar' => Barryvdh\Debugbar\Facade::class,

/**
Expand Down
18 changes: 18 additions & 0 deletions config/snappy.php
Original file line number Diff line number Diff line change
@@ -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' => [],
],
];
5 changes: 3 additions & 2 deletions resources/assets/sass/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,6 +55,7 @@
display: flex;
flex-direction: column;
border: 1px solid #DDD;
width: 50%;
}
.markdown-display {
padding: 0 $-m 0;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/revisions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 3f0ef57

Please sign in to comment.