Created
August 16, 2013 21:11
-
-
Save somoza/6253550 to your computer and use it in GitHub Desktop.
PDF Plugin
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
./symfony plugin:install SfTCPDFPlugin | |
IMPORTANTE: Copiar clase de la libreria de plugins/sfTCPDFPlugin/lib copiar de proyecto existente (camara o bariloche). | |
LOGO del PDF: Esta dentro de /plugins/sfTCPDFPlugin/lib/tcpdf/images/logo.png | |
Archivo: apps/backend/config/pdf_configs.yml | |
Snipet: | |
$newPdf = $this->createPdf($this->getPartial('report', array( | |
'previusCc'=>$this->previusCc, | |
'ccEntrySubtotal'=>$this->ccEntrySubtotal, | |
'date'=>$this->date, | |
'arrEntries'=>$this->arrEntries, | |
'ccEntries'=>$this->ccEntries, | |
'caEntries'=>$this->caEntries, | |
'ccEgressSubtotal'=>$this->ccEgressSubtotal, | |
'arrEgresses'=>$this->arrEgresses, | |
'ccEgresses'=>$this->ccEgresses, | |
'caEgresses'=>$this->caEgresses, | |
'previusCa'=>$this->previusCa, | |
'caEntrySubtotal'=>$this->caEntrySubtotal, | |
'caEgressSubtotal'=>$this->caEgressSubtotal | |
)), $this->date); | |
metodo privado en action | |
private function createPdf($html, $date) | |
{ | |
$config = sfTCPDFPluginConfigHandler::loadConfig(); | |
// pdf object | |
$pdf = new sfTCPDF(); | |
// set document information | |
$pdf->SetCreator(PDF_CREATOR); | |
$pdf->SetAuthor('Cámara de Comercio e Industria de San Carlos de Bariloche'); | |
$pdf->SetTitle('Reporte Mensual '.$date); | |
$pdf->SetSubject('Reporte Mensual Cámara de Comercio de Bariloche'); | |
$pdf->SetKeywords('reporte, camara, comercio'); | |
// set default header data | |
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.$date, PDF_HEADER_STRING); | |
// set header and footer fonts | |
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); | |
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); | |
// set default monospaced font | |
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); | |
//set margins | |
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); | |
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); | |
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); | |
//set auto page breaks | |
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); | |
//set image scale factor | |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); | |
// --------------------------------------------------------- | |
// set default font subsetting mode | |
$pdf->setFontSubsetting(true); | |
// Set font | |
// dejavusans is a UTF-8 Unicode font, if you only need to | |
// print standard ASCII chars, you can use core fonts like | |
// helvetica or times to reduce file size. | |
$pdf->SetFont('dejavusans', '', 14, '', true); | |
// Add a page | |
// This method has several options, check the source code documentation for more information. | |
$pdf->AddPage(); | |
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); | |
$pdf->Output(dirname(__FILE__).'/../../../../../web/uploads/reports/reporte-'.$date.'.pdf', 'F'); | |
return '/uploads/reports/reporte-'.$date.'.pdf'; | |
// Stop symfony process | |
throw new sfStopException(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment