Source for file pdfexport.php
Documentation is available at pdfexport.php
* Construct a PDF from the array representation
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* path (bumblebee root)/inc/export/pdfexport.php
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'inc/bb/configreader.php';
/** constants for defining export formatting and codes */
require_once 'inc/exportcodes.php';
/** config and class libraries for PDF export */
require_once 'inc/export/pdfexportconfig.php';
* Construct a PDF from the array representation
var $rowLines =
''; // use 'T' for lines between rows
var $headerLines =
'TB'; // Top and Bottom lines on the header rows
var $cols =
array(); //=array(50,20,20,20,20,20,20,20); //column widths
$this->ea =
$exportArray;
$this->pdf->AliasNbPages();
#$this->pdf->AddPage(); //should we always include a page to start with?
return $this->pdf->Output('', 'S');
$metaData =
$this->ea->export['metadata'];
$this->pdf->SetCreator($metaData['creator']);
$this->pdf->SetAuthor($metaData['author']);
$this->pdf->SetKeywords($metaData['keywords']);
$this->pdf->SetSubject($metaData['subject']);
$this->pdf->SetTitle($metaData['title']);
$this->pdf->title =
$metaData['title'];
'orientation', 'size', 'pageWidth', 'pageHeight',
'leftMargin', 'rightMargin', 'topMargin', 'bottomMargin',
'minAutoMargin', 'tableHeaderAlignment', 'rowLines', 'headerLines',
'normalLineHeight', 'headerLineHeight', 'footerLineHeight', 'sectionHeaderLineHeight',
'doubleLineWidth', 'singleLineWidth', 'singleCellTopMargin'
'normalFillColor', 'normalDrawColor', 'normalTextColor', 'normalFont',
'sectionHeaderFillColor', 'sectionHeaderDrawColor', 'sectionHeaderTextColor', 'sectionHeaderFont',
'tableHeaderFillColor', 'tableHeaderDrawColor', 'tableHeaderTextColor', 'tableHeaderFont',
'tableFooterFillColor', 'tableFooterDrawColor', 'tableFooterTextColor', 'tableFooterFont',
'tableTotalFillColor', 'tableTotalDrawColor', 'tableTotalTextColor', 'tableTotalFont'
foreach ($simplevars as $v) {
$this->$v =
$conf->value('pdfexport', $v);
foreach ($cxvars as $v) {
$val =
$conf->value('pdfexport', $v);
$fonts =
$conf->value('pdfexport', 'fontSubstitutions');
foreach ($fontList as $font) {
$fontTable["@$line[0]@i"] =
$line[1];
$vars =
array('pageWidth', 'pageHeight', 'leftMargin', 'rightMargin', 'topMargin', 'bottomMargin', 'minAutoMargin', 'tableHeaderAlignment', 'rowLines', 'headerLines');
$this->pdf->$v =
$this->$v;
'normalLineHeight', 'headerLineHeight', 'footerLineHeight', 'sectionHeaderLineHeight',
'doubleLineWidth', 'singleLineWidth', 'singleCellTopMargin',
'normalFillColor', 'normalDrawColor', 'normalTextColor', 'normalFont',
'sectionHeaderFillColor', 'sectionHeaderDrawColor', 'sectionHeaderTextColor', 'sectionHeaderFont',
'tableHeaderFillColor', 'tableHeaderDrawColor', 'tableHeaderTextColor', 'tableHeaderFont',
'tableFooterFillColor', 'tableFooterDrawColor', 'tableFooterTextColor', 'tableFooterFont',
'tableTotalFillColor', 'tableTotalDrawColor', 'tableTotalTextColor', 'tableTotalFont',
$this->pdf->$v =
$this->$v;
* calculate column widths
* @todo //TODO: make sure PDF columns don't go over right side of page
$this->log('Calculating column widths');
for ($col =
0; $col<
count($widths); $col++
) {
if ($widths[$col] ==
'*') {
//if ($taken > ($this->pageWidth-$this->leftMargin-$this->rightMargin)) {
///FIXME: must not go over page right
for ($col =
0; $col<
count($widths); $col++
) {
if (! isset
($this->cols[$col])) {
$this->cols[$col] =
$widths[$col]
* Calculate the width of an actual column
* @todo //TODO: calculate width of header from actual header data (bold) rather than 1.1 * non-bold
//why are we doing lots of calls into the pdf here? is it bad encapsulation?
//We have to have a font chosen within FPDF to perform these length calculations
$this->pdf->_setTableFont();
$ea =
& $this->ea->export;
//$this->log('key='.$key);
if (is_array($ea[$key]['data'])) { // protect against headers
$newWidth =
$this->pdf->GetStringWidth($ea[$key]['data'][$col]['value']);
$newWidth *=
1.1; //FIXME: we should do this calculation properly!
//echo "VAL=".$ea[$key]['data'][$col]['value'].", WIDTH=$newWidth/$width.<br/>";
$width =
max($width, $newWidth);
//echo "WIDTH=$width.<br/>";
//FIXME: is this random thing good enough? what about fitting in the header?
//why are we doing lots of calls into the pdf here? is it bad encapsulation?
//We have to have a font chosen within FPDF to perform these length calculations
$this->pdf->_setTableFont();
$ea =
& $this->ea->export;
while ($rows<
10 ||
$header<
1) {
$newWidth =
$this->pdf->GetStringWidth($ea[$key]['data'][$col]['value']);
//echo "VAL=".$ea[$key]['data'][$col]['value'].", WIDTH=$newWidth/$width.<br/>";
$width =
max($width, $newWidth);
$newWidth =
1.1*
$this->pdf->GetStringWidth($ea[$key]['data'][$col]['value']);
//echo "VAL=".$ea[$key]['data'][$col]['value'].", WIDTH=$newWidth/$width.<br/>";
$width =
max($width, $newWidth);
//echo "WIDTH=$width.<br/>";
//$this->log('Making HTML representation of data');
$ea =
& $this->ea->export;
$metaData =
$ea['metadata'];
$this->log('Found '.
$ea_length.
' rows in this ExportArray');
for ($i=
0; $i<
$ea_length; $i++
) {
#echo $i.': '.$ea[$i]['type'].'<br/>';
switch ($ea[$i]['type']) {
$this->pdf->reportStart();
$this->pdf->reportHeader($ea[$i]['data']);
$this->pdf->sectionHeader($ea[$i]['data']);
$this->pdf->tableStart();
$this->pdf->tableHeader($this->_formatRow($ea[$i]['data'], true));
$this->pdf->tableTotal($this->_formatRow($ea[$i]['data'], false, 'TT'));
/// FIXME: free memory as we are using it up
function _formatRow($row, $isHeader=
false, $border=
NULL) {
for ($j=
0; $j<
count($row); $j++
) {
$rowpdf[] =
$this->_formatCell($row[$j], $j, $isHeader, $border);
function _formatCell($d, $col, $isHeader, $setborder) {
return array('align'=>
$align, 'value'=>
$val, 'fill'=>
$fill, 'border'=>
$border);
function log ($string, $prio=
10) {
if ($prio <=
$this->DEBUG) {
* PDF class that extends FPDF by putting the logo in the top corner
function BrandedPDF($orientation, $measure, $format) {
parent::TCPDF($orientation, $measure, $format);
$this->title =
T_('Bumblebee Report');
$this->Image('theme/export/logo.png',10,8,33);
$this->Cell(200,30,$this->title,0,0,'C');
//Position at 1.5 cm from bottom
$this->Cell(0,10,'Page '.
$this->PageNo().
'/{nb}',0,0,'C');
return parent::SetFillColor($r[0], $r[1], $r[2]);
return parent::SetFillColor($r, $g, $b);
return parent::SetDrawColor($r[0], $r[1], $r[2]);
return parent::SetDrawColor($r, $g, $b);
return parent::SetTextColor($r[0], $r[1], $r[2]);
return parent::SetTextColor($r, $g, $b);
function SetFont($font=
0, $style=
0, $size=
0) {
return parent::SetFont($this->_substituteFont($font[0]), $font[1], $font[2]);
function log ($string, $prio=
10) {
if ($prio <=
$this->DEBUG) {
// overload the error function to give us some better output
echo
'<div class="error"><b>'.
T_('Error generating PDF output:').
'</b><br/> '.
$msg
.
'<br/><br/>'.
T_('Sorry things didn\'t work out for you.').
'</div>';
die(T_('Exiting with error'));
* PDF class that extends BrandedPDF by providing functions for representing row data.
* Table-managing code adapted from Olivier's FPDF examples:
* http://www.fpdf.org/en/script/script3.php
function TabularPDF($orientation, $measure, $format) {
parent::BrandedPDF($orientation, $measure, $format);
$this->AddPage(); // FIXME: doesn't add a page if no section header??
//Colors, line width and bold font
$this->_row(array(array('value'=>
$header,'border'=>
'','align'=>
'L', 'fill'=>
true, 'fullWidth'=>
1)));
//$data[0]['fullWidth'] = 1;
$this->_row(array(array('value'=>
'','border'=>
'T','fill'=>
false,'fullWidth'=>
0)));
if (count($data) ==
1 && isset
($data[0]['fullWidth']) &&
$data[0]['fullWidth'] ==
1) {
} elseif (count($data) ==
1) {
//Calculate the height of the row
for($i=
0; $i<
count($data); $i++
)
$nb=
max($nb, $this->NbLines($widths[$i], $data[$i]['value']));
//Issue a page break first if needed
//Draw the cells of the row
for($i=
0; $i<
count($data); $i++
) {
$align=isset
($data[$i]['align']) ?
$data[$i]['align'] :
'L';
//Save the current position
//Draw the background of the cell if appropriate
$this->Rect($x, $y0bg, $widths[$i], $rowHeight+
$this->cellTopMargin, 'F');
//Draw the borders requested
if ($data[$i]['border']) {
if (strpos($data[$i]['border'], 'B') !==
false) {
$this->line($x, $y0txt+
$rowHeight, $x+
$widths[$i], $y0txt+
$rowHeight);
if (strpos($data[$i]['border'], 'T') !==
false) {
$this->line($x, $y0bg, $x+
$widths[$i], $y0bg);
if (strpos($data[$i]['border'], 'TT') !==
false) {
//double line on the top of the cell
$this->line($x, $y0bg+
$dy, $x+
$widths[$i], $y0bg+
$dy);
if (strpos($data[$i]['border'], 'L') !==
false) {
$this->line($x, $y0bg, $x, $y0txt+
$rowHeight);
if (strpos($data[$i]['border'], 'R') !==
false) {
$this->line($x+
$widths[$i], $y0bg, $x+
$widths[$i], $y0txt+
$rowHeight);
$this->MultiCell($widths[$i], $this->lineHeight, $data[$i]['value'], '', $align, 0);
//Put the position to the right of the cell
$this->SetXY($x+
$widths[$i],$y0txt);
//If the height h would cause an overflow, add a new page immediately
$this->AddPage($this->CurOrientation);
//Computes the number of lines a MultiCell of width w will take
$cw=
&$this->CurrentFont['cw'];
$w=
$this->w-
$this->rMargin-
$this->x;
$wmax=
($w-
2*
$this->cMargin)*
1000/
$this->FontSize;
if($nb>
0 and $s[$nb-
1]==
"\n")
if(isset
($cw[ord($c)])) {
/// FIXME: Making up a width... probably should warn the user
Documentation generated on Tue, 06 Mar 2007 10:01:52 +0000 by phpDocumentor 1.3.0