Files
InvoiceShelf/app/Services/PDFService.php
Tim van Osch bf40f792c2 Feat(Gotenberg): Opt-in alternative pdf generation for modern CSS (#184)
* WIP(gotenberg): add pdf generation abstraction and UI

* feat(pdf): settings validate(clien+server) & save

* fix(gotenberg): Use correct default papersize
chore(gotengberg): Remove unused GOTENBERG_MARGINS env from .env

* style(gotenberg): fix linter/styling issues

* fix(pdf): use pdf config policy

* fix: revert accidental capitalization in mail config vue

* Update composer, remove whitespace typo

* Fix small typos

* fix cookie/env issue

* Add gotenberg to .dev, move admin menu item up
2025-05-04 02:10:15 +02:00

48 lines
933 B
PHP

<?php
namespace App\Services;
/*
* Two options:
* - Barryvdh\DomPDF\Facade\Pdf
* - Gotenberg
*/
use App;
use App\Services\PDFDrivers\GotenbergPDFDriver;
use Illuminate\Http\Response;
interface ResponseStream
{
public function stream(string $filename): Response;
public function output(): string;
}
interface PDFDriver
{
public function loadView(string $template): ResponseStream;
}
class PDFDriverFactory
{
public static function create(string $driver)
{
return match ($driver) {
'dompdf' => App::make('dompdf.wrapper'),
'gotenberg' => new GotenbergPDFDriver,
default => throw new \InvalidArgumentException('Invalid PDFDriver requested')
};
}
}
class PDFService
{
public static function loadView(string $template)
{
$driver = config('pdf.driver');
return PDFDriverFactory::create($driver)->loadView($template);
}
}