|
|
@@ -17,7 +17,8 @@ class PdfEncoder implements EncoderInterface
|
|
|
protected Options $domPdfOptions;
|
|
|
protected Dompdf $dompdf;
|
|
|
|
|
|
- public function __construct() {
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
$this->domPdfOptions = new Options();
|
|
|
$this->dompdf = new Dompdf();
|
|
|
}
|
|
|
@@ -30,16 +31,17 @@ class PdfEncoder implements EncoderInterface
|
|
|
/**
|
|
|
* Converts the provided HTML content into a PDF document.
|
|
|
*
|
|
|
- * @param string $html The HTML content to be converted to PDF.
|
|
|
+ * @param string $html the HTML content to be converted to PDF
|
|
|
* @param array<string, mixed> $options Optional configuration settings for the PDF generation
|
|
|
+ *
|
|
|
* @see https://github.com/dompdf/dompdf/blob/master/src/Options.php
|
|
|
*
|
|
|
- * @return string The generated PDF content as a string.
|
|
|
+ * @return string the generated PDF content as a string
|
|
|
*/
|
|
|
public function encode(string $html, array $options = []): string
|
|
|
{
|
|
|
$this->domPdfOptions->setIsRemoteEnabled(true);
|
|
|
- $this->domPdfOptions->setChroot(Path::getProjectDir() . '/public');
|
|
|
+ $this->domPdfOptions->setChroot(Path::getProjectDir().'/public');
|
|
|
$this->domPdfOptions->setDefaultPaperOrientation('portrait');
|
|
|
$this->domPdfOptions->setDefaultPaperSize('A4');
|
|
|
$this->domPdfOptions->set($options);
|
|
|
@@ -47,6 +49,7 @@ class PdfEncoder implements EncoderInterface
|
|
|
$this->dompdf->setOptions($this->domPdfOptions);
|
|
|
$this->dompdf->loadHtml($html);
|
|
|
$this->dompdf->render();
|
|
|
+
|
|
|
return $this->dompdf->output();
|
|
|
}
|
|
|
}
|