Skip to content

Instantly share code, notes, and snippets.

@katgirl
Last active January 4, 2016 06:29
Show Gist options
  • Save katgirl/8582244 to your computer and use it in GitHub Desktop.
Save katgirl/8582244 to your computer and use it in GitHub Desktop.
Isotope mit PDF-Footer
<?php
/**
* Generate a PDF file and optionally send it to the browser
* @param string
* @param object
* @param boolean
*/
public function generatePDF($strTemplate=null, $pdf=null, $blnOutput=true)
{
if (!is_object($pdf))
{
// TCPDF configuration
$l['a_meta_dir'] = 'ltr';
$l['a_meta_charset'] = $GLOBALS['TL_CONFIG']['characterSet'];
$l['a_meta_language'] = $GLOBALS['TL_LANGUAGE'];
$l['w_page'] = 'page';
// Include library
require_once(TL_ROOT . '/system/config/tcpdf.php');
require_once(TL_ROOT . '/plugins/tcpdf/mytcpdf.php');
// Prevent TCPDF from destroying absolute paths
unset($_SERVER['DOCUMENT_ROOT']);
// Create new PDF document
$pdf = new MYTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
// Set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor(PDF_AUTHOR);
// Remove default header
$pdf->setPrintHeader(false);
// Create Footer
$pdf->setPrintFooter(true);
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// Set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// Set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
// Set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// Set some language-dependent strings
$pdf->setLanguageArray($l);
// Set font
$pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN);
}
// Start new page
$pdf->AddPage();
// Write the HTML content
$pdf->writeHTML($this->generate($strTemplate, false), true, 0, true, 0);
if ($blnOutput)
{
// Close and output PDF document
// @todo $strInvoiceTitle is not defined
$pdf->lastPage();
$pdf->Output(standardize(ampersand($strInvoiceTitle, false), true) . '.pdf', 'D');
// Stop script execution
exit;
}
return $pdf;
}
<?php
$GLOBALS['TL_LANG']['CUSTOM']['PDF_FOOTER'] = '
<table style="width:100%">
<tr>
<td>Spalte 1</td>
<td>Spalte 2</td>
<td>Spalte 3</td>
</tr>
</table>';
<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf.php');
// Extend the TCPDF class to create custom Footer
class MYTCPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->writeHTML($GLOBALS['TL_LANG']['CUSTOM']['PDF_FOOTER'], true, 0, true, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment