Skip to content

Instantly share code, notes, and snippets.

@davidchc
Created July 6, 2018 01:01
Show Gist options
  • Save davidchc/2b93cd544446f4295bbc3db734c64d43 to your computer and use it in GitHub Desktop.
Save davidchc/2b93cd544446f4295bbc3db734c64d43 to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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