Reputation: 283
I'm using dompdf to try and convert html into a pdf file. The file was created no problem but when I tried to open the file, it was corrupt. When I opened the file in notepad, I could see it was just the raw html. So it hadn't converted anything at all, it had just put it in a file with an extension of pdf.
Here is my code:
include_once '/files/dompdf/dompdf_config.inc.php';
$files = glob("/files/dompdf/include/*.php");
foreach($files as $file) include_once($file);
ob_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Title
</title>
</head>
<body>
<div><p>Hello World</p></div>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
This just grabs the html exactly as it is written here and saves it as sample.pdf but its not a proper pdf file. Am I missing something?
Upvotes: 0
Views: 1935
Reputation: 283
I fixed it by stripping slashes. This is the updated:
$html = ob_get_clean();
if ( get_magic_quotes_gpc() )
$html = stripslashes($html);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
Upvotes: 1