radfusion/app/Services/Export/Formats/PdfExport.php
2025-01-10 17:51:53 +06:00

34 lines
905 B
PHP

<?php
namespace app\Services\Export\Formats;
use App\Domain\Report\ExportFormat;
use App\Services\Export\ExportDocumentBase;
use App\Services\ReportStorage;
use Barryvdh\DomPDF\Facade\Pdf;
final class PdfExport extends ExportDocumentBase
{
protected function handle(): string
{
$filename = $this->filename();
$filepath = ReportStorage::customFilepath($this->study, $filename);
if (ReportStorage::exists($this->study, $filename)) {
return $filepath;
}
$data = ['report' => $this->report, 'title' => 'PDF VIEW'];
Pdf::loadView('staff.reports.viewer.html-report', $data)
->setPaper('a4', 'landscape')
->setWarnings(false)
->save(ReportStorage::abspath($filepath));
return $filepath;
}
protected function getExtension(): string
{
return ExportFormat::Pdf->value;
}
}