mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
* 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
48 lines
933 B
PHP
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);
|
|
}
|
|
}
|