Created
September 3, 2010 16:31
-
-
Save jaredhoyt/564138 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 | |
App::import('Vendor', 'DOMPDF', array('file' => 'dompdf' . DS . 'dompdf_config.inc.php')); | |
class CustomPDF extends DOMPDF { | |
public function Header() { | |
# Header code goes here | |
} | |
public function Footer() { | |
# Footer code goes here | |
} | |
} | |
class PdfView extends View { | |
function render($action = null, $layout = null, $file = null) { | |
# Grab rendered html and clear self::output | |
$renderedTemplate = parent::render($action, $layout, $file); | |
$this->output = ''; | |
# Create new PDF document | |
$pdf = new CustomPDF(); | |
# Write HTML to PDF | |
$pdf->load_html($renderedTemplate); | |
$pdf->set_paper('letter', 'portrait'); | |
$pdf->render(); | |
$renderedTemplate = ''; | |
# Output generated PDF | |
$pdf->stream($this->getVar('filename') . '.pdf', array('Attachment' => true)); | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment