Files
rkm-conectasus-ci-sandbox/api/app/Utils/Exports/Pdf.php
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

56 lines
1.1 KiB
PHP

<?php
namespace App\Utils\Exports;
use Dompdf\Dompdf;
use Dompdf\Options;
class Pdf
{
private Dompdf $dompdf;
public function __construct(Options $options = null)
{
$this->dompdf = new Dompdf($options ?? $this->getDefaultOptions());
$this->setPaper('A4', 'portrait');
}
private function getDefaultOptions() : Options
{
$options = new Options;
$options->set('isPhpEnabled', true);
return $options;
}
public function setPaper(string $type, string $orientation) : void
{
$this->dompdf->setPaper($type, $orientation);
}
public function stream(string $html, string $fileName = 'documento')
{
$this->dompdf->loadHtml($html);
$this->dompdf->render();
return response()->streamDownload(
function () {
echo $this->dompdf->output();
},
"{$fileName}.pdf",
['Content-Type' => 'Application/pdf']
);
}
public function output(string $html)
{
$this->dompdf->loadHtml($html);
$this->dompdf->render();
return $this->dompdf->output();
}
}