-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
I get this error from dompdf but its only when i attempt to save the file ($savePDF is true). As you can see below I have tried various things but still get the error. I'm certain the error is being logged from DomPDF.
PHP Error: [2] DOMXPath::query(): Invalid expression in /vendor/dompdf/dompdf/src/Css/Stylesheet.php on line 1047
My Code:
if(isset($savePDF) && $savePDF){
// Save the generated PDF to a temporary file
$pdfFilePath = $root . 'tmp/' . $fileName . '.pdf';
// file_put_contents($pdfFilePath, $dompdf->output());
$output = $dompdf->output();
if ($output === false) {
throw new Exception("Dompdf output failed");
}
file_put_contents($pdfFilePath, $output);
// file_put_contents($pdfFilePath, $dompdf->output(), LOCK_EX);
// $dompdf->stream($pdfFilePath, ["Attachment" => false]);
// $handle = fopen($pdfFilePath, 'wb');
// if ($handle) {
// fwrite($handle, $dompdf->output());
// fclose($handle);
// } else {
// die("Error: Unable to write to $pdfFilePath");
// }
}
else{
// Output the PDF as a download
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='document.pdf'");
echo $dompdf->output();
}