Reputation: 3690
I'm using dompdf for a project I'm building, and part of the project requires a report to be generated in a PDF format.
In the HTML version of the report, I have some of the details of the report displayed in an iFrame like this:
<?php foreach ($jobsheets as $jobsheet) { ?>
<iframe src="http://localhost/modal/customers/<?php echo $company['Company']['id']; ?>/jobs/<?php echo $jobsheet['Jobsheet']['id']; ?>/viewlite/" id="jbif<?php echo $jobsheet['Jobsheet']['id']; ?>" frameborder="0" width="975px" height="272px" scrolling="no" class="<?php echo $jobsheet['Jobsheet']['jobdate']; ?>"></iframe>
<?php } ?>
However, the PDF that is being generated without rendering these iframes. Is there anything I can do to make the dompdf module render them, or will I have to physically include the data without the use of iframes?
Upvotes: 1
Views: 4219
Reputation: 41
To display a pdf file generated from dompdf, try to save the file to disk and then call inside the object tag.
PHP
try {
$buffer = ob_get_contents();
ob_clean();
$dompdf = new \Dompdf\Dompdf();
$dompdf->setPaper('A4');
$dompdf->loadHtml($buffer);
$dompdf->set_option('isHtml5ParserEnabled', true);
// Render the HTML as PDF
$dompdf->render();
// save the generated PDF to Browser
file_put_contents('file.pdf', $dompdf->output());
chmod('file.pdf', 0777);
} catch (Exception $ex) {
echo $ex->getMessage();
}
HTML
<html>
<head>
<title>FILE PDF</title>
</head>
<body style="margin: 0; padding: 0">
<div style="width: 740px; margin-left: auto; height: 20%; padding: 0; margin: 0;">
<a href="">SEND PDF</a>
</div>
<object data="http://<?=$_SERVER['HTTP_HOST']?>/file.pdf" type="application/pdf" style="margin: 0; width:100%; height: 80%; padding: 0;">
<embed src="http://<?=$_SERVER['HTTP_HOST']?>/file.pdf" type="application/pdf" />
</object>
</body>
Upvotes: 2
Reputation: 140195
Dompdf doesn't support rendering iframes inside a document. You can submit an issue in the tracker. You'll need to use something else for now.
Upvotes: 3