tempDir = $tempDir; } public function generate($html, array $options=[]) { $pdf = new Dompdf(); $pdf->loadHtml($html); $pdf->render(); $output = $pdf->output(); return $output; } public function generateResponseFromHtml($html, array $options=[]) { $tempFile = $this->tempDir . "/" . "pdf_" . md5(uniqid()) . ".pdf"; // Call on generate with the options provided $output = $this->generate($html, $options); file_put_contents($tempFile, $output); // Prepare the response $response = new BinaryFileResponse($tempFile); if (array_key_exists('filename', $options)) { $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $options['filename']); } else { $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE); } $response->deleteFileAfterSend(true); return $response; } }