Created
February 10, 2011 15:48
-
-
Save jaredhoyt/820739 to your computer and use it in GitHub Desktop.
PdfView for tcpdf
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', 'tcPDF', array('file' => 'tcpdf' . DS . 'tcpdf.php')); | |
class CustomPDF extends TCPDF { | |
public function Footer() { | |
} | |
public function Header() { | |
} | |
} | |
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(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', true); | |
# Set document information | |
$pdf->SetCreator(''); | |
$pdf->SetAuthor(''); | |
$pdf->SetTitle(''); | |
$pdf->SetSubject(''); | |
$pdf->SetKeywords(''); | |
$pdf->setPrintHeader(true); | |
$pdf->setPrintFooter(true); | |
# Set margins | |
$pdf->SetMargins(10, 15, 10); | |
# Set auto page breaks | |
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); | |
# Set image scale factor | |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); | |
# Write HTML to PDF | |
$pdf->AddPage(); | |
$pdf->writeHTML($renderedTemplate, true, 0, true, 0); | |
$renderedTemplate = ''; | |
# Output generated PDF. 'D' is to force a download, uses the filename view var to name the file | |
$this->output = $pdf->Output($this->getVar('filename') . '.pdf', 'D'); | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment