Closed
Description
The PDF generation fails without error message for big html files (and web server never send any response, web browser waiting indefinitely for a response).
I add to stop using this php wrapper and use passthru() to generate PDF contents.
My old code :
$pdf->addPage($html);
$content = $pdf->toString();
My new code :
$tmpfname = tempnam(sys_get_temp_dir(), "tmp_pdf_");
rename($tmpfname, $tmpfname .= '.html');
$tmpfnameOut = tempnam(sys_get_temp_dir(), "tmp_pdf_");
rename($tmpfnameOut, $tmpfnameOut .= '.pdf');
$handle = fopen($tmpfname, "w");
fwrite($handle, $html);
fclose($handle);
$cmd = "wkhtmltopdf $tmpfname $tmpfnameOut 2>&1"; // 2>&1 to output error messages
ob_start();
passthru($cmd, $retval);
$result = ob_get_clean();
if($retval){
die("Error with command: $cmd<br />Error code '$retval'<br />". nl2br(htmlentities($result)));
}
unlink($tmpfname);
$content = file_get_contents($tmpfnameOut);
unlink($tmpfnameOut);
Metadata
Metadata
Assignees
Labels
No labels