2010-03-25 04:27:33 +00:00
|
|
|
<?
|
|
|
|
|
|
|
|
require_once('tcpdf_config.php');
|
|
|
|
require_once('tcpdf/tcpdf.php');
|
|
|
|
|
|
|
|
class pdf extends TCPDF {
|
|
|
|
|
|
|
|
/* Variables for labels */
|
|
|
|
var $label_width, $label_height;
|
|
|
|
var $label_xspacer, $label_yspacer;
|
|
|
|
var $label_rows, $label_cols, $labels_per_page;
|
|
|
|
var $label_page_lmargin, $label_page_tmargin;
|
|
|
|
var $label_show_fair, $label_show_box, $label_show_logo;
|
|
|
|
var $current_label_index;
|
|
|
|
|
2010-03-30 07:02:15 +00:00
|
|
|
var $footer_string;
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
function __construct($report_name='', $format='LETTER', $orientation='P')
|
|
|
|
{
|
2010-11-03 17:18:02 +00:00
|
|
|
global $conference;
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
/* Start an output PDF */
|
|
|
|
|
|
|
|
/* Orientation - Page orientation:
|
|
|
|
* P or Portrait (default)
|
|
|
|
* L or Landscape */
|
|
|
|
// $orientation = 'P';
|
|
|
|
|
|
|
|
/* Units - User measure unit:
|
|
|
|
/* We're going to do everything in mm and convert, even if we worked
|
|
|
|
* in pts (1/72 of an inch) we'd still need decimals */
|
|
|
|
|
|
|
|
/* Format - Page size
|
|
|
|
It can be either one of the following values (case insensitive) or
|
|
|
|
a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).
|
|
|
|
* 4A0 * 2A0 * A0 * A1 * A2 * A3 * A4 (default) * A5 * A6 * A7 * A8 * A9 * A10
|
|
|
|
* B0 * B1 * B2 * B3 * B4 * B5 * B6 * B7 * B8 * B9 * B10
|
|
|
|
* C0 * C1 * C2 * C3 * C4 * C5 * C6 * C7 * C8 * C9 * C10
|
|
|
|
* RA0 * RA1 * RA2 * RA3 * RA4
|
|
|
|
* SRA0 * SRA1 * SRA2 * SRA3 * SRA4
|
|
|
|
* LETTER * LEGAL * EXECUTIVE * FOLIO
|
|
|
|
* array($width, $height) */
|
|
|
|
// $format = 'LETTER';
|
|
|
|
|
|
|
|
/* Other args: true = turn on unicode,
|
|
|
|
set encoding to UTF-8,
|
|
|
|
turn off temp-files-on-disk */
|
|
|
|
parent::__construct($orientation, 'mm', $format, true, 'UTF-8', false);
|
|
|
|
|
|
|
|
// set document information
|
|
|
|
$this->SetCreator('SFIAB');
|
|
|
|
$this->SetAuthor('SFIAB');
|
2010-11-03 17:18:02 +00:00
|
|
|
$this->SetTitle(i18n($conference['name']));
|
2010-03-25 04:27:33 +00:00
|
|
|
$this->SetSubject($report_name);
|
|
|
|
$this->SetKeywords('');
|
|
|
|
|
2010-11-03 17:18:02 +00:00
|
|
|
/* Set default header data (K_PATH_IMAGES/[conference id]-logo-500.jpg, 16mm wide, header, name)
|
2010-03-31 05:52:52 +00:00
|
|
|
* PDFs use JPG internally, so we should feed it a jpeg, if we dont', tcpdf will
|
|
|
|
* convert it to a jpg anyway, and that takes FOREVER if there's lots of
|
|
|
|
* pages/labels.*/
|
2011-02-23 22:33:30 +00:00
|
|
|
$this->SetHeaderData($conference['id'] . '-logo-500.png', 16 /* mm */,
|
2010-11-03 17:18:02 +00:00
|
|
|
i18n($conference['name']), i18n($report_name));
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
// set header and footer fonts
|
2010-03-30 07:02:15 +00:00
|
|
|
$this->setHeaderFont(Array('helvetica', '', 14));
|
|
|
|
$this->setFooterFont(Array('helvetica', '', 8));
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
// set default monospaced font
|
|
|
|
$this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
|
|
|
|
|
//set margins
|
2011-03-14 20:59:16 +00:00
|
|
|
$this->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP+4, PDF_MARGIN_RIGHT);
|
2010-03-25 04:27:33 +00:00
|
|
|
$this->SetHeaderMargin(PDF_MARGIN_HEADER);
|
|
|
|
$this->SetFooterMargin(PDF_MARGIN_FOOTER);
|
|
|
|
|
|
|
|
//set auto page breaks
|
|
|
|
$this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
2010-03-30 07:02:15 +00:00
|
|
|
$this->setPrintFooter(TRUE);
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
//set image scale factor
|
|
|
|
$this->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
|
|
|
|
|
$this->current_label_index = 1;
|
|
|
|
$this->current_label_row = 0;
|
|
|
|
$this->current_label_col = 0;
|
|
|
|
|
2010-03-30 07:02:15 +00:00
|
|
|
$this->footer_string = date("Y-m-d h:ia").' - '.$report_name;
|
|
|
|
|
|
|
|
|
2010-03-25 04:27:33 +00:00
|
|
|
//set some language-dependent strings
|
|
|
|
//$this->setLanguageArray($l);
|
|
|
|
//print_r($this->fontlist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-08 18:49:20 +00:00
|
|
|
/* Given a cell of width $w, format $txt so it fits into that
|
|
|
|
* width, using as many lines as necessary, with
|
|
|
|
* font ($fontname, $fontstyle, $fontsize).
|
|
|
|
* - fontsize is in points
|
|
|
|
* Returns an array of lines that fit in the width.
|
|
|
|
* Compute the final height with:
|
|
|
|
* count($lines) * ($this->cMargin * 2 + $fontsize_not_in_pts) */
|
|
|
|
function _cell_lines($w,$txt,$fontname, $fontstyle, $fontsize)
|
2010-03-25 04:27:33 +00:00
|
|
|
{
|
|
|
|
$index = 0;
|
|
|
|
$lines = array();
|
|
|
|
|
|
|
|
/* Get an array of widths */
|
2010-06-08 18:49:20 +00:00
|
|
|
$width = $this->getStringWidth($txt,$fontname, $fontstyle,$fontsize,true);
|
2010-03-25 04:27:33 +00:00
|
|
|
$chars = $this->UTF8StringToArray($txt);
|
|
|
|
$count = count($width); // strlen(utf8_decode($txt));
|
|
|
|
|
|
|
|
$curr_width = $this->cMargin * 2;
|
|
|
|
$last_space_index = -1;
|
|
|
|
$start_index = 0;
|
|
|
|
|
|
|
|
for($index=0; $index<$count;$index++) {
|
|
|
|
$newline = false;
|
|
|
|
$skip = false;
|
|
|
|
|
|
|
|
/* Special chars */
|
|
|
|
switch($this->unichr($chars[$index])) {
|
|
|
|
case ' ': case "\r": case "\t":
|
|
|
|
$last_space_index = $index;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "\n":
|
|
|
|
$newline = true;
|
|
|
|
$skip = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for width overflow */
|
|
|
|
if($skip == true) {
|
|
|
|
/* Do nothing with it */
|
|
|
|
} else if ($curr_width + $width[$index] > $w) {
|
|
|
|
/* Backup index, leave it pointing to
|
|
|
|
* the last char we print, so when we
|
|
|
|
* increment in the next iteration we
|
|
|
|
* get the next char (the one that just
|
|
|
|
* caused this overflow */
|
|
|
|
$index--;
|
|
|
|
$newline = true;
|
|
|
|
} else {
|
|
|
|
$curr_width += $width[$index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if($newline) {
|
|
|
|
if($last_space_index != -1) {
|
|
|
|
/* Backup to the last space index, if there is one */
|
|
|
|
$end_index = $last_space_index;
|
|
|
|
$index = $last_space_index;
|
|
|
|
} else {
|
|
|
|
/* No, use the whole line then */
|
|
|
|
$end_index = $index;
|
|
|
|
}
|
|
|
|
$lines[] = $this->UTF8ArrSubString($chars,$start_index,$end_index);
|
|
|
|
/* Reset width, set start index */
|
|
|
|
$curr_width = $this->cMargin * 2;
|
|
|
|
$last_space_index = -1;
|
|
|
|
$start_index = $index+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$lines[] = $this->UTF8ArrSubString($chars,$start_index,$index);
|
|
|
|
return $lines;
|
|
|
|
}
|
|
|
|
/* Cell( float $w, [float $h = 0], [string $txt = ''], [mixed $border = 0],
|
|
|
|
[int $ln = 0], [string $align = ''], [int $fill = 0], [mixed $link = ''],
|
|
|
|
[int $stretch = 0], [boolean $ignore_min_height = false]) */
|
|
|
|
|
|
|
|
|
|
|
|
function FitCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$valign='',$on_overflow='scale')
|
|
|
|
{
|
|
|
|
$x = $this->getX();
|
|
|
|
$y = $this->getY();
|
|
|
|
$orig_fs = $this->getFontSizePt();
|
2010-04-03 08:48:20 +00:00
|
|
|
$add_ellipses = false;
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
$fontsize = $orig_fs;
|
|
|
|
while(1) {
|
2010-06-08 18:49:20 +00:00
|
|
|
$lines = $this->_cell_lines($w, $txt, '', '', $fontsize);
|
2010-03-25 04:27:33 +00:00
|
|
|
|
2010-06-08 18:49:20 +00:00
|
|
|
/* this->FontSize is always correct, we change $fontisze
|
|
|
|
* below, but then use that to set the internal fontsize */
|
2010-04-03 08:48:20 +00:00
|
|
|
$cell_height = $this->cMargin * 2 + $this->FontSize;
|
2010-06-08 18:49:20 +00:00
|
|
|
$total_height = $cell_height * count($lines);
|
2010-04-03 08:48:20 +00:00
|
|
|
|
2010-06-08 18:49:20 +00:00
|
|
|
if($total_height <= $h) {
|
2010-03-25 04:27:33 +00:00
|
|
|
/* It fits! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-03 08:48:20 +00:00
|
|
|
/* else, it doesn't fit */
|
2010-03-25 04:27:33 +00:00
|
|
|
if($on_overflow == 'scale') {
|
|
|
|
/* reduce the font size and try again */
|
|
|
|
$fontsize -= 0.5;
|
|
|
|
$this->setFontSize($fontsize);
|
|
|
|
continue;
|
2010-04-03 08:48:20 +00:00
|
|
|
}
|
2010-03-25 04:27:33 +00:00
|
|
|
|
2010-04-03 08:48:20 +00:00
|
|
|
/* If it doesn't fit, and we're not scaling, it must
|
|
|
|
* be a truncate. Compute the number of lines that
|
|
|
|
* can be displayed */
|
|
|
|
$display_lines = floor($h / $cell_height);
|
|
|
|
/* Adjust height */
|
|
|
|
$label_h -= (count($lines) - $display_lines) * $cell_height;
|
|
|
|
|
|
|
|
/* truncate */
|
|
|
|
$lines = array_slice($lines, 0, $display_lines);
|
|
|
|
|
|
|
|
if($on_overflow == '...') $add_ellipses = true;
|
|
|
|
break;
|
2010-03-25 04:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SetX, find Y based on alignment */
|
|
|
|
switch($valign) {
|
|
|
|
case 'M': /* Middle */
|
2010-06-08 18:49:20 +00:00
|
|
|
$this->SetXY($x, $y + ($h - $total_height) / 2);
|
2010-03-25 04:27:33 +00:00
|
|
|
break;
|
|
|
|
case 'B': /* Bottom */
|
2010-06-08 18:49:20 +00:00
|
|
|
$this->SetXY($x, $y + ($h - $total_height));
|
2010-03-25 04:27:33 +00:00
|
|
|
break;
|
|
|
|
case 'T': default: /* Top */
|
|
|
|
$this->SetXY($x, $y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-03 08:48:20 +00:00
|
|
|
/* Fontsize will be correctly set here */
|
2010-03-25 04:27:33 +00:00
|
|
|
/* Cell( float $w, [float $h = 0], [string $txt = ''], [mixed $border = 0],
|
|
|
|
[int $ln = 0], [string $align = ''], [int $fill = 0], [mixed $link = ''],
|
|
|
|
[int $stretch = 0], [boolean $ignore_min_height = false]) */
|
|
|
|
foreach($lines as $l) {
|
|
|
|
$this->Cell($w, 0, $l, 0, 2, $align, 0, 0, 0, false);
|
|
|
|
}
|
|
|
|
|
2010-04-03 08:48:20 +00:00
|
|
|
if($add_ellipses) {
|
|
|
|
/* Only use fontsize so the '...' is really close to the lower right. */
|
|
|
|
$this->SetXY($x, $y + $h - $cell_height);
|
|
|
|
$this->Cell($w, 0, '...', 0, 0, 'R');
|
|
|
|
}
|
2010-03-25 04:27:33 +00:00
|
|
|
|
|
|
|
/* Restore original location */
|
|
|
|
$this->SetXY($x,$y);
|
|
|
|
|
2010-04-03 08:48:20 +00:00
|
|
|
/* Restore original fontsize */
|
|
|
|
$this->setFontSize($orig_fs);
|
|
|
|
|
2010-06-08 18:49:20 +00:00
|
|
|
/* Print a Cell to print the border (if we're supposed to), and
|
|
|
|
* to leave x,y wherever $ln tells us to */
|
2010-04-03 08:48:20 +00:00
|
|
|
$this->Cell($w, $h, '', $border, $ln, 'R');
|
2010-06-08 18:49:20 +00:00
|
|
|
|
|
|
|
return $total_height;
|
2010-03-25 04:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function GetFontList()
|
|
|
|
{
|
|
|
|
if(!is_object($this)) {
|
|
|
|
$pdf = new pdf();
|
|
|
|
return $pdf->GetFontList();
|
|
|
|
}
|
|
|
|
$this->getFontsList();
|
|
|
|
return $this->fontlist;
|
|
|
|
}
|
|
|
|
|
2010-03-30 07:02:15 +00:00
|
|
|
function Footer()
|
|
|
|
{
|
|
|
|
$ormargins = $this->getOriginalMargins();
|
|
|
|
$pagenumtxt = i18n('Page').' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
|
|
|
|
|
|
|
|
$this->SetX($ormargins['left']);
|
|
|
|
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
|
|
|
|
|
|
|
|
$this->SetX($ormargins['left']);
|
|
|
|
$this->Cell(0, 0, $this->footer_string, 0, 0, 'C');
|
|
|
|
}
|
|
|
|
|
2010-03-25 04:27:33 +00:00
|
|
|
function setup_for_labels($show_box, $show_fair, $show_logo, $width, $height, $xspacer, $yspacer, $rows, $cols)
|
|
|
|
{
|
|
|
|
/* No headers and footers */
|
|
|
|
$this->setPrintHeader(false);
|
|
|
|
$this->setPrintFooter(false);
|
|
|
|
|
|
|
|
/* No auto-pagebreaks */
|
|
|
|
$this->SetAutoPageBreak(false);
|
|
|
|
|
|
|
|
|
|
|
|
/* the page size/orientation is already set */
|
|
|
|
$pw = $this->getPageWidth();
|
|
|
|
$ph = $this->getPageHeight();
|
|
|
|
|
|
|
|
$this->label_show_box = $show_box;
|
|
|
|
$this->label_show_fair = $show_fair;
|
|
|
|
$this->label_show_logo = $show_logo;
|
|
|
|
|
|
|
|
$this->label_width=$width;
|
|
|
|
$this->label_height=$height;
|
|
|
|
$this->label_xspacer=$xspacer;
|
|
|
|
$this->label_yspacer=$yspacer;
|
|
|
|
|
|
|
|
$this->label_rows=$rows;
|
|
|
|
$this->label_cols=$cols;
|
|
|
|
$this->labels_per_page=$rows * $cols;
|
|
|
|
|
|
|
|
/* labels are always centered in the page */
|
|
|
|
|
|
|
|
$this->label_page_lmargin=( $pw - ($cols*$width) - ($xspacer*($cols-1)) )/2;
|
|
|
|
$this->label_page_tmargin=( $ph - ($rows*$height) - ($yspacer*($rows-1)) )/2;
|
|
|
|
|
|
|
|
/* Setup so that the first call to label_new also creates
|
|
|
|
* a new page */
|
|
|
|
$this->current_label_index = $this->labels_per_page - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function label_new()
|
|
|
|
{
|
|
|
|
/* Advance to new label */
|
|
|
|
// echo "cindex=$this->current_label_index, perpage=$this->labels_per_page\n";
|
|
|
|
if($this->current_label_index + 1 == $this->labels_per_page) {
|
|
|
|
// echo "addpage\n";
|
|
|
|
$this->AddPage();
|
|
|
|
$this->current_label_index = 0;
|
|
|
|
} else {
|
|
|
|
$this->current_label_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get row/col, and position of label */
|
|
|
|
$r = floor($this->current_label_index / $this->label_cols);
|
|
|
|
$c = floor($this->current_label_index % $this->label_cols);
|
|
|
|
|
|
|
|
$lmargin = $this->label_page_lmargin + ($c * ($this->label_width + $this->label_xspacer) );
|
|
|
|
$tmargin = $this->label_page_tmargin + ($r * ($this->label_height + $this->label_yspacer) );
|
|
|
|
|
|
|
|
/* Move margins for this label */
|
|
|
|
// echo "r=$r, c=$c, cols=$this->label_cols\n";
|
|
|
|
// echo "Margins -> ($lmargin, $tmargin)\n";
|
|
|
|
$this->SetMargins($lmargin, $tmargin, $lmargin + $this->label_width);
|
|
|
|
|
|
|
|
if($this->label_show_box)
|
|
|
|
$this->label_rect(0,0,$this->label_width, $this->label_height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* align = left, center, right
|
|
|
|
valign = top, middle, bottom,
|
|
|
|
fontname,
|
|
|
|
fontstyle,
|
|
|
|
fontsize,
|
|
|
|
border = true/false
|
|
|
|
on_overflow = truncate, ..., scale */
|
2010-06-08 18:49:20 +00:00
|
|
|
|
2010-03-25 04:27:33 +00:00
|
|
|
function label_text($x,$y,$w,$h,$text,$border,$align,$valign,$fontname,$fontstyle,$fontsize,
|
|
|
|
$on_overflow)
|
|
|
|
{
|
|
|
|
$orig_name = $this->getFontFamily();
|
|
|
|
$orig_style = $this->getFontStyle();
|
|
|
|
$orig_size = $this->getFontSizePt();
|
|
|
|
$orig_x = $this->GetX();
|
|
|
|
$orig_y = $this->GetY();
|
|
|
|
|
|
|
|
/* Do horiz/vert align */
|
|
|
|
$align_data = array('left' => 'L', 'center' => 'C', 'right' => 'R');
|
|
|
|
$valign_data = array('top' => 'T', 'middle' => 'M', 'bottom' => 'B');
|
|
|
|
$align = $align_data[$align];
|
|
|
|
$valign = $valign_data[$valign];
|
|
|
|
|
|
|
|
/* Set position and font */
|
|
|
|
$st = array('bold' => 'B', 'italic' => 'I', 'underline' => 'U', 'strikethrough' => 'D');
|
|
|
|
$fs = '';
|
|
|
|
if(is_array($fontstyle)) {
|
|
|
|
foreach($fontstyle as $s) $fs .= $st[$s];
|
|
|
|
}
|
|
|
|
|
|
|
|
if($fontsize == 0) $fontsize = 10; /* FIXME: getdefaultfontsize? */
|
|
|
|
|
|
|
|
$this->SetXY($this->lMargin + $x,$this->tMargin + $y);
|
|
|
|
// echo "position (x,y)=($x,$y)\n";
|
|
|
|
// echo "margin (l,t)=({$this->lMargin},{$this->tMargin})\n";
|
|
|
|
// echo "(x,y)=(".($this->lMargin + $x).",".($this->tMargin + $y).")\n";
|
|
|
|
$this->SetFont($fontname, $fs, $fontsize);
|
|
|
|
|
|
|
|
/* Print text */
|
|
|
|
$this->FitCell($w,$h, $text, $border ? 1 : 0, 2,
|
|
|
|
$align, $valign, $on_overflow);
|
|
|
|
|
|
|
|
/* Restore position and font */
|
|
|
|
$this->SetFont($orig_name, $orig_style, $orig_size);
|
|
|
|
$this->SetXY($orig_x, $orig_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function label_rect($x,$y,$w,$h)
|
|
|
|
{
|
|
|
|
$this->Rect($this->lMargin + $x, $this->tMargin + $y, $w, $h);
|
|
|
|
}
|
2010-06-08 18:49:20 +00:00
|
|
|
|
2010-06-09 07:43:59 +00:00
|
|
|
function label_fair_logo($x, $y, $w, $h, $show_box)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$img_dir = $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY'].'/data';
|
|
|
|
/* Scale image to proportinally fit in w x h */
|
2011-02-23 22:33:30 +00:00
|
|
|
$this->Image($img_dir."/".$conference['id']."-logo-500.png", $this->lMargin + $x, $this->tMargin + $y,
|
2010-06-09 07:43:59 +00:00
|
|
|
$w, $h, '', '', '', true,
|
|
|
|
300, '', false, false, $show_box ? 1 : 0, true);
|
|
|
|
}
|
|
|
|
|
2010-06-08 18:49:20 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Table handling */
|
|
|
|
function hr()
|
|
|
|
{
|
|
|
|
$this->Cell(0, 1, '', 'B', 1, '');
|
|
|
|
$this->Cell(0, 1, '', '', 1, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function vspace($space)
|
|
|
|
{
|
|
|
|
$this->SetY($this->GetY() + $space);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup_for_tables($show_box, $show_fair, $show_logo, $width, $height, $xspacer, $yspacer, $rows, $cols)
|
|
|
|
{
|
|
|
|
$this->SetFont('times', '', 10);
|
|
|
|
|
|
|
|
/* Need to start with a page if autopagebreak is on */
|
|
|
|
$this->addPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function heading($text)
|
|
|
|
{
|
|
|
|
/* TCPDF will spill this cell over to the next page if the height
|
|
|
|
* doesn't fit, so we don't have to do any height calculations, just
|
|
|
|
* create an oversized cell with nothing in it to force a spillover if
|
|
|
|
* at least the first table row won't fit with the header */
|
|
|
|
/* header font size + 5mm + curr font size (2st table rows)*/
|
|
|
|
$h = ($this->FontSize * 1.5) + 5 + ($this->FontSize * 2);
|
|
|
|
$this->Cell(0, $h, '', 0, 2, '', 0, 0, 0, false);
|
|
|
|
$this->SetY($this->GetY() - $h);
|
|
|
|
|
|
|
|
/* Now print it in a normal sized cell with a bit of bottom padding
|
|
|
|
* before the table starts */
|
|
|
|
$h = ($this->FontSize * 1.5) + 5;
|
|
|
|
$orig = $this->getFontSizePt();
|
|
|
|
$this->setFont('', 'B', $orig * 1.5);
|
|
|
|
$this->Cell(0, $h, $text, 0, 2, '', 0, 0, 0, false);
|
|
|
|
$this->setFont('', '', $orig);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generates the HTML for a table */
|
|
|
|
function get_table_html($table)
|
|
|
|
{
|
|
|
|
// echo "Add Table\n<pre>";
|
|
|
|
// print_r($table);
|
|
|
|
/* Compute the lines in height of each row for pagination */
|
|
|
|
|
|
|
|
$html = '<table border="1" cellpadding="2"><thead><tr>';
|
|
|
|
foreach($table['col'] as $c=>$col) {
|
|
|
|
$html .= "<td width=\"{$col['width']}mm\" align=\"center\"><b>{$col['header']}</b></td>";
|
|
|
|
}
|
|
|
|
$html .= '</tr></thead>';
|
|
|
|
|
|
|
|
// echo "<pre>";
|
|
|
|
|
|
|
|
/* Width of "..." */
|
|
|
|
$e_width = $this->getStringWidth('...', '', '', '', false);
|
|
|
|
|
|
|
|
foreach($table['data'] as $row) {
|
|
|
|
$html .= '<tr>';
|
|
|
|
foreach($row as $c => $d) {
|
|
|
|
/* unfortunately, HTML doesn't do overflow the
|
|
|
|
* way we want, so compute the width of each cell
|
|
|
|
* and truncate the text if needed */
|
|
|
|
if($table['col'][$c]['on_overflow'] == '...') {
|
|
|
|
// echo "check for overflow... $d";
|
|
|
|
/* See if $d fits in the allowed width */
|
|
|
|
$width = $this->getStringWidth($d, '', '', '', true);
|
|
|
|
$target_w = $table['col'][$c]['width'];
|
|
|
|
/* FIXME, this doesn't work all the time
|
|
|
|
* there must be some cellpadding that HTML is doing */
|
|
|
|
$target_w -= 1.4111111111; /* 2 points * 2*/
|
|
|
|
$target_w -= 0.7055555556; /* 2 points */
|
|
|
|
|
|
|
|
$cw = 0;
|
|
|
|
// echo "target=$target_w, w=";
|
|
|
|
// print_r($width);
|
|
|
|
for($x=0; $x<count($width); $x++) {
|
|
|
|
$w = $width[$x];
|
|
|
|
// echo "w=$w, total=".($cw+$w)." target=$target_w\n";
|
|
|
|
if($cw + $w > $target_w) {
|
|
|
|
/* Overflow */
|
|
|
|
while($x >= 0) {
|
|
|
|
$x--;
|
|
|
|
$cw -= $width[$x];
|
|
|
|
if($cw + $e_width < $target_w) break;
|
|
|
|
}
|
|
|
|
$d = substr($d, 0, $x).'...';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$cw += $w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "<td width=\"{$table['col'][$c]['width']}mm\" align=\"{$table['col'][$c]['align']}\">$d</td>";
|
|
|
|
}
|
|
|
|
$html .= '</tr>';
|
|
|
|
}
|
|
|
|
$html .= '</table>';
|
|
|
|
return $html;
|
|
|
|
}
|
2010-06-08 19:24:26 +00:00
|
|
|
|
2011-02-22 15:24:19 +00:00
|
|
|
function addTable($table)
|
2010-06-08 18:49:20 +00:00
|
|
|
{
|
|
|
|
$orig_lmargin = $this->lMargin;
|
|
|
|
$orig_tmargin = $this->tMargin;
|
|
|
|
|
|
|
|
$html = $this->get_table_html($table);
|
|
|
|
$total_width = 0;
|
|
|
|
foreach($table['col'] as $c=>$col)
|
|
|
|
$total_width += $col['width'];
|
|
|
|
|
|
|
|
$lpad = (($this->getPageWidth() - $this->lMargin - $this->rMargin) - $total_width)/2;
|
|
|
|
|
|
|
|
$this->SetLeftMargin($orig_lmargin + $lpad);
|
|
|
|
$this->writeHTML($html, false, false, false, false, '');
|
|
|
|
$this->SetLeftMargin($orig_lmargin);
|
|
|
|
|
|
|
|
if($table['total'] != 0) {
|
|
|
|
$this->Cell($total_width, 0, "(Total: {$table['total']})", 0, 1, 'R');
|
|
|
|
} else {
|
|
|
|
$t = count($table['data']);
|
|
|
|
$this->Cell($total_width, 0, "(Rows: $t)", 0, 1, 'R');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function output($filename='', $dest='I')
|
|
|
|
{
|
|
|
|
if($filename == '') {
|
|
|
|
$filename=strtolower($this->subject);
|
|
|
|
$filename=ereg_replace("[^a-z0-9]","_",$filename).'.pdf';
|
|
|
|
}
|
2011-02-21 22:07:06 +00:00
|
|
|
return parent::Output($filename, $dest);
|
2010-06-08 18:49:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 04:27:33 +00:00
|
|
|
}
|