// Application Service Providers
'providers' => ServiceProvider::defaultProviders()->merge([
// Third party service providers
- Barryvdh\Snappy\ServiceProvider::class,
SocialiteProviders\Manager\ServiceProvider::class,
// BookStack custom service providers
// 2024-04: Snappy/WKHTMLtoPDF now considered deprecated in regard to BookStack support.
'snappy' => [
- 'pdf' => [
- 'enabled' => true,
- 'binary' => file_exists(base_path('wkhtmltopdf')) ? base_path('wkhtmltopdf') : env('WKHTMLTOPDF', false),
- 'timeout' => false,
- 'options' => [
- 'outline' => true,
- 'page-size' => $snappyPaperSizeMap[$exportPageSize] ?? 'A4',
- ],
- 'env' => [],
- ],
- 'image' => [
- 'enabled' => false,
- 'binary' => '/usr/local/bin/wkhtmltoimage',
- 'timeout' => false,
- 'options' => [],
- 'env' => [],
+ 'pdf_binary' => env('WKHTMLTOPDF', false),
+ 'options' => [
+ 'print-media-type' => true,
+ 'outline' => true,
+ 'page-size' => $snappyPaperSizeMap[$exportPageSize] ?? 'A4',
],
],
namespace BookStack\Entities\Tools;
-use Barryvdh\Snappy\Facades\SnappyPdf;
+use Knp\Snappy\Pdf as SnappyPdf;
use Dompdf\Dompdf;
class PdfGenerator
$engine = $this->getActiveEngine();
if ($engine === self::ENGINE_WKHTML) {
- $pdf = SnappyPDF::loadHTML($html);
- $pdf->setOption('print-media-type', true);
- return $pdf->output();
+ return $this->renderUsingWkhtml($html);
} else if ($engine === self::ENGINE_COMMAND) {
// TODO - Support PDF command
return '';
*/
public function getActiveEngine(): string
{
- $wkhtmlBinaryPath = config('snappy.pdf.binary');
- if (file_exists(base_path('wkhtmltopdf'))) {
- $wkhtmlBinaryPath = base_path('wkhtmltopdf');
- }
-
- if (is_string($wkhtmlBinaryPath) && config('app.allow_untrusted_server_fetching') === true) {
+ if ($this->getWkhtmlBinaryPath() && config('app.allow_untrusted_server_fetching') === true) {
return self::ENGINE_WKHTML;
}
return self::ENGINE_DOMPDF;
}
+ protected function getWkhtmlBinaryPath(): string
+ {
+ $wkhtmlBinaryPath = config('exports.snappy.pdf_binary');
+ if (file_exists(base_path('wkhtmltopdf'))) {
+ $wkhtmlBinaryPath = base_path('wkhtmltopdf');
+ }
+
+ return $wkhtmlBinaryPath ?: '';
+ }
+
protected function renderUsingDomPdf(string $html): string
{
$options = config('exports.dompdf');
return (string) $domPdf->output();
}
+ protected function renderUsingWkhtml(string $html): string
+ {
+ $snappy = new SnappyPdf($this->getWkhtmlBinaryPath());
+ $options = config('exports.snappy.options');
+ return $snappy->getOutputFromHtml($html, $options);
+ }
+
/**
* Taken from https://github.com/barryvdh/laravel-dompdf/blob/v2.1.1/src/PDF.php
* Copyright (c) 2021 barryvdh, MIT License
"ext-mbstring": "*",
"ext-xml": "*",
"bacon/bacon-qr-code": "^2.0",
- "barryvdh/laravel-snappy": "^1.0",
"doctrine/dbal": "^3.5",
"dompdf/dompdf": "^2.0",
"guzzlehttp/guzzle": "^7.4",
"intervention/image": "^3.5",
+ "knplabs/knp-snappy": "^1.5",
"laravel/framework": "^10.10",
"laravel/socialite": "^5.10",
"laravel/tinker": "^2.8",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "c0c5a3169cb23d9ab8e34324202d4c37",
+ "content-hash": "97259e40ffe5518cfcdf1e32eacbb175",
"packages": [
{
"name": "aws/aws-crt-php",
},
"time": "2022-12-07T17:46:57+00:00"
},
- {
- "name": "barryvdh/laravel-snappy",
- "version": "v1.0.3",
- "source": {
- "type": "git",
- "url": "https://github.com/barryvdh/laravel-snappy.git",
- "reference": "716dcb6db24de4ce8e6ae5941cfab152af337ea0"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/716dcb6db24de4ce8e6ae5941cfab152af337ea0",
- "reference": "716dcb6db24de4ce8e6ae5941cfab152af337ea0",
- "shasum": ""
- },
- "require": {
- "illuminate/filesystem": "^9|^10|^11.0",
- "illuminate/support": "^9|^10|^11.0",
- "knplabs/knp-snappy": "^1.4.4",
- "php": ">=7.2"
- },
- "require-dev": {
- "orchestra/testbench": "^7|^8|^9.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0-dev"
- },
- "laravel": {
- "providers": [
- "Barryvdh\\Snappy\\ServiceProvider"
- ],
- "aliases": {
- "PDF": "Barryvdh\\Snappy\\Facades\\SnappyPdf",
- "SnappyImage": "Barryvdh\\Snappy\\Facades\\SnappyImage"
- }
- }
- },
- "autoload": {
- "psr-4": {
- "Barryvdh\\Snappy\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Barry vd. Heuvel",
- }
- ],
- "description": "Snappy PDF/Image for Laravel",
- "keywords": [
- "image",
- "laravel",
- "pdf",
- "snappy",
- "wkhtmltoimage",
- "wkhtmltopdf"
- ],
- "support": {
- "issues": "https://github.com/barryvdh/laravel-snappy/issues",
- "source": "https://github.com/barryvdh/laravel-snappy/tree/v1.0.3"
- },
- "funding": [
- {
- "url": "https://fruitcake.nl",
- "type": "custom"
- },
- {
- "url": "https://github.com/barryvdh",
- "type": "github"
- }
- ],
- "time": "2024-03-09T19:20:39+00:00"
- },
{
"name": "brick/math",
"version": "0.11.0",
* [Google Material Icons](https://github.com/google/material-design-icons) - _[Apache-2.0](https://github.com/google/material-design-icons/blob/master/LICENSE)_
* [markdown-it](https://github.com/markdown-it/markdown-it) and [markdown-it-task-lists](https://github.com/revin/markdown-it-task-lists) - _[MIT](https://github.com/markdown-it/markdown-it/blob/master/LICENSE) and [ISC](https://github.com/revin/markdown-it-task-lists/blob/master/LICENSE)_
* [Dompdf](https://github.com/dompdf/dompdf) - _[LGPL v2.1](https://github.com/dompdf/dompdf/blob/master/LICENSE.LGPL)_
-* [BarryVD/Snappy (WKHTML2PDF)](https://github.com/barryvdh/laravel-snappy) - _[MIT](https://github.com/barryvdh/laravel-snappy/blob/master/LICENSE)_
+* [KnpLabs/snappy](https://github.com/KnpLabs/snappy) - _[MIT](https://github.com/KnpLabs/snappy/blob/master/LICENSE)_
* [WKHTMLtoPDF](http://wkhtmltopdf.org/index.html) - _[LGPL v3.0](https://github.com/wkhtmltopdf/wkhtmltopdf/blob/master/LICENSE)_
* [diagrams.net](https://github.com/jgraph/drawio) - _[Embedded Version Terms](https://www.diagrams.net/trust/) / [Source Project - Apache-2.0](https://github.com/jgraph/drawio/blob/dev/LICENSE)_
* [OneLogin's SAML PHP Toolkit](https://github.com/onelogin/php-saml) - _[MIT](https://github.com/onelogin/php-saml/blob/master/LICENSE)_