Created
July 6, 2018 01:01
-
-
Save davidchc/2b93cd544446f4295bbc3db734c64d43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace View; | |
class Template | |
{ | |
public function render($file, $args=[]) | |
{ | |
extract($this->data); | |
ob_start(); | |
include($file); | |
$content = ob_get_contents(); | |
ob_end_clean(); | |
return $content; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$options = new Dompdf\Options(); | |
$options->set('isRemoteEnabled', true); | |
$options->set('isHtml5ParserEnabled', true); | |
$options->set('isPhpEnabled', true); | |
$dompdf = new Dompdf\Dompdf($options); | |
$template = new View\Template(); | |
$html = $template->render('pages/pdf.php'); | |
$dompdf->loadHtml($html); | |
$dompdf->setPaper('a4', 'landscape'); | |
$dompdf->render(); | |
$dompdf->stream("exemplo.pdf", array('Attachment' => 0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment