|
@@ 40-52 (lines=13) @@
|
| 37 |
|
$this->eventDispatcher = $eventDispatcher; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
public function streamHtml(string $html, string $filename, array $options = []): void |
| 41 |
|
{ |
| 42 |
|
$pdf = $this->dompdfFactory->create($options); |
| 43 |
|
$pdf->loadHtml($html); |
| 44 |
|
$pdf->render(); |
| 45 |
|
|
| 46 |
|
if ($this->eventDispatcher instanceof EventDispatcherInterface) { |
| 47 |
|
$event = new StreamEvent($pdf, $filename, $html); |
| 48 |
|
$this->eventDispatcher->dispatch($event, DompdfEvents::STREAM); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
$pdf->stream($filename, $options); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
public function getStreamResponse(string $html, string $filename, array $options = []): StreamedResponse |
| 55 |
|
{ |
|
@@ 64-82 (lines=19) @@
|
| 61 |
|
return $response; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
public function getPdf(string $html, array $options = []): string |
| 65 |
|
{ |
| 66 |
|
$pdf = $this->dompdfFactory->create($options); |
| 67 |
|
$pdf->loadHtml($html); |
| 68 |
|
$pdf->render(); |
| 69 |
|
|
| 70 |
|
if ($this->eventDispatcher instanceof EventDispatcherInterface) { |
| 71 |
|
$event = new OutputEvent($pdf, $html); |
| 72 |
|
$this->eventDispatcher->dispatch($event, DompdfEvents::OUTPUT); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
$out = $pdf->output(); |
| 76 |
|
|
| 77 |
|
if (null === $out) { |
| 78 |
|
throw new PdfException('Error creating PDF document'); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
return $out; |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|