QR_code_generator/app/Services/Documents/GeneratePdfDocument.php

35 lines
980 B
PHP

<?php
namespace App\Services\Documents;
use Barryvdh\DomPDF\Facade as PDF;
use Illuminate\Support\Facades\Storage;
class GeneratePdfDocument extends DocumentGeneratorService {
public array $options = [
'orientation' => 'portrait'
];
public string $fontName = 'Times New Roman';
public int $fontSize = 10;
public function __construct(string $template, array $data, array $options) {
$template = "documents.pdf.{$template}";
parent::__construct($template, $data, $options);
}
public function file(): string {
$pdf = PDF::loadView($this->template, $this->data);
if ($this->options['orientation'] === 'landscape') $pdf->setPaper('a4', 'landscape');
$filePath = $this->makeFilePath('pdf');
Storage::put($filePath, $pdf->download()->getOriginalContent());
return $filePath;
}
public function asset(string $name) {
return $this->makeAsset($this->file(), $name);
}
}