TCPDF support library and label generation code that uses TCPDF. All

other stuff still works, this only adds on.  And on second thought, I
should probably disable the report type that would let someone use this.
This commit is contained in:
dave 2010-03-25 04:27:33 +00:00
parent be6c5a27c9
commit 8ee1f36f90
6 changed files with 783 additions and 24 deletions

View File

@ -33,6 +33,7 @@
require_once('../lpdf.php');
require_once('../lcsv.php');
require_once('../tcpdf.inc.php');
$filter_ops = array( 0 => '=',
1 => '<=',
@ -48,7 +49,7 @@
$report_options = array();
$report_options['type'] = array('desc' => 'Report Format',
'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label')
'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label', 'tcpdf_label'=>'TCPDF Label')
);
$report_options['group_new_page'] = array('desc' => 'Start each new grouping on a new page',
'values' => array('no'=>'No', 'yes'=>'Yes')
@ -105,6 +106,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 9.5,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['fullpage_landscape'] = array('name' => 'Letter 8.5 x 11 Landscape (3/4" margin)',
@ -116,6 +119,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 7,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'L',
);
$report_stock['fullpage_full'] = array('name' => 'Letter 8.5 x 11 (no margin)',
@ -127,6 +132,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 11,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['fullpage_landscape_full'] = array('name' => 'Letter 8.5 x 11 Landscape (no margin)',
@ -138,6 +145,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 8.5,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'L',
);
$report_stock['5161'] = array('name' => 'Avery 5161/5261/5961/8161, G&T 99189 (1"x4")',
@ -150,6 +159,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'y_spacing' => 0.00,
'y_padding' => 0.05,
'rows' => 10,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['5162'] = array('name' => 'Avery 5162/5262/5962/8162/8462, G&T 99190 (1 1/3"x4")',
@ -162,6 +173,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'y_spacing' => 0.00,
'y_padding' => 0.30,
'rows' => 7,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['5163'] = array('name' => 'Avery 5163/5263/5963/8163/8463, G&T 99181 (2"x4")',
'page_width' => 8.5,
@ -172,6 +185,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 2,
'y_spacing' => 0.00,
'rows' => 5,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
/* This is combined with 5161
@ -196,6 +211,9 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 3 + 1/3,
'y_spacing' => 0,
'rows' => 3,
'page_format' => 'LETTER', /* tcpdf format */
'page_orientation' => 'P', /* tcpdf orientation */
);
$report_stock['nametag'] = array('name' => 'Cards 4"x3"',
'page_width' => 8.5,
@ -206,6 +224,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 3,
'y_spacing' => 0,
'rows' => 3,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['letter_4up'] = array('name' => 'Fullpage, 4up',
@ -217,6 +237,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 5,
'y_spacing' => 0.25,
'rows' => 2,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['ledger'] = array('name' => 'Ledger/Tabloid 11 x 17',
@ -228,6 +250,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 17,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
$report_stock['ledger_landscape'] = array('name' => 'Ledger/Tabloid 11 x 17 Landscape',
@ -239,6 +263,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
'label_height' => 11,
'y_spacing' => 0,
'rows' => 1,
'page_format' => 'LETTER',
'page_orientation' => 'P',
);
@ -322,24 +348,30 @@ foreach($report_stock as $n=>$v) {
$x = 0;
foreach($report[$type] as $k=>$v) {
if($type == 'option') {
/* field, value, x, y, w, h, lines, face, align */
$vals = "'$k','$v','0','0','0','0','0','',''";
/* field, value, x, y, w, h, lines, face, align, valign, fn, fs, fsize, overflow */
$vals = "'$k','$v','0','0','0','0','0','','','','','','0','truncate'";
} else {
if($v['lines'] == 0) $v['lines'] =1;
$fs = is_array($v['fontstyle']) ? implode(',',$v['fontstyle']) : '';
$opts = "{$v['align']} {$v['valign']}";
$vals = "'{$v['field']}','{$v['value']}',
'{$v['x']}','{$v['y']}','{$v['w']}',
'{$v['h']}','{$v['lines']}','{$v['face']}',
'$opts'";
'$opts','{$v['valign']}',
'{$v['fontname']}','$fs','{$v['fontsize']}',
'{$v['on_overflow']}'";
}
if($q != '') $q .= ',';
$q .= "({$report['id']}, '$type','$x',$vals)";
$x++;
}
mysql_query("INSERT INTO reports_items(`reports_id`,`type`,`ord`,
`field`,`value`,`x`, `y`, `w`, `h`,
`lines`, `face`, `align`)
`lines`, `face`, `align`,`valign`,
`fontname`,`fontstyle`,`fontsize`,`on_overflow`)
VALUES $q;");
echo mysql_error();
}
@ -404,8 +436,11 @@ foreach($report_stock as $n=>$v) {
}
/* Pull out all the data */
$val = array();
$col_fields = array('field', 'x', 'y', 'w', 'h', 'lines', 'face', 'align', 'value');
$col_fields = array('field', 'x', 'y', 'w', 'h', 'lines', 'face', 'align', 'valign', 'value', 'fontname','fontsize','on_overflow');
foreach($col_fields as $lf) $val[$lf] = $a[$lf];
$val['fontstyle'] = explode(',', $a['fontstyle']);
/* valign, fontname, fontsize,fontstyle are unused, except in tcpdf reports
(i.e. nothign has changed, only adding on */
if($val['lines'] == 0) $val['lines'] = 1;
$opts = explode(" ", $val['align']);
@ -422,6 +457,7 @@ foreach($report_stock as $n=>$v) {
break;
}
}
//`int_r($report);
return $report;
}
@ -448,9 +484,7 @@ foreach($report_stock as $n=>$v) {
}
/*
print("<pre>");
/* print("<pre>");
print_r($_POST);
print_r($report);
print("</pre>");
@ -577,6 +611,20 @@ foreach($report_stock as $n=>$v) {
if($report['option']['allow_multiline'] == 'yes')
$table['option']['allow_multiline'] = true;
break;
case 'tcpdf_label':
$label_stock = $report_stock[$report['option']['stock']];
$show_box = ($report['option']['label_box'] == 'yes') ? true : false;
$show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false;
$show_logo = ($report['option']['label_logo'] == 'yes') ? true : false;
$rep=new pdf($report['name'], $label_stock['page_format'], $label_stock['page_orientation']);
$rep->setup_for_labels($show_box, $show_fair, $show_logo,
$label_stock['label_width'] * 25.4, $label_stock['label_height'] * 25.4,
$label_stock['x_spacing'] * 25.4, $label_stock['y_spacing'] * 25.4,
$label_stock['rows'], $label_stock['cols']);
$gen_mode = 'tcpdf_label';
break;
default:
echo "Invalid type [{$report['option']['type']}]";
exit;
@ -737,6 +785,8 @@ foreach($report_stock as $n=>$v) {
$n_groups = count($report['group']);
$last_group_data = array();
// echo "<pre>";print_r($rep);
while($i = mysql_fetch_assoc($r)) {
if($n_groups > 0) {
@ -789,7 +839,10 @@ foreach($report_stock as $n=>$v) {
$show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false;
$show_logo = ($report['option']['label_logo'] == 'yes') ? true : false;
$rep->newLabel($show_box, $show_fair, $show_logo);
} else if($gen_mode == 'tcpdf_label') {
$rep->label_new();
}
foreach($report['col'] as $o=>$d) {
$f = $d['field'];
if(is_array($fields[$f]['value_map'])) {
@ -826,6 +879,23 @@ foreach($report_stock as $n=>$v) {
$d['h'], $lh,
$v, $opt);
}
} else if($gen_mode == 'tcpdf_label') {
/* Setup additional options */
$show_box = ($report['option']['field_box'] == 'yes') ? true : false;
// echo "<pre>"; print_r($d);
if($f == 'static_box') {
$rep->label_rect($d['x'], $d['y'], $d['w'], $d['h']);
} else {
if($f == 'static_text') $v = $d['value'];
$rep->label_text($d['x'], $d['y'], $d['w'], $d['h'],
$v, $show_box, $d['align'], $d['valign'],
$d['fontname'],$d['fontstyle'],$d['fontsize'],
$d['on_overflow']);
}
}
if($fields[$f]['total'] == true)
@ -836,6 +906,8 @@ foreach($report_stock as $n=>$v) {
if(count($table['data'])) {
$rep->addTable($table);
}
$rep->output();
}

View File

@ -36,6 +36,7 @@
require_once('reports_fairs.inc.php');
require_once('reports_fundraising.inc.php');
require_once('reports.inc.php');
require_once('../tcpdf.inc.php');
$fields = array();
$locs = array('X' => 'x', 'Y' => 'y', 'W' => 'w', 'H' => 'h', 'Lines' => 'lines');
@ -89,7 +90,7 @@
exit;
}
} else if($l == 'valign') {
$aligns = array('vtop', 'vbottom', 'vcenter');
$aligns = array('vtop', 'vbottom', 'vcenter', 'top','middle','bottom');
if(!in_array($v, $aligns)) {
echo "Invalid valignment $v";
exit;
@ -186,10 +187,14 @@ function reportReload()
var canvasWidth=0;
var canvasHeight=0;
var canvasObjectIndex=0;
var labelWidth=0;
var labelHeight=0;
function initCanvas(w,h) {
function initCanvas(w,h,lw,lh) {
canvasWidth=w;
canvasHeight=h;
labelWidth=lw;
labelHeight=lh;
}
function createData(x,y,w,h,l,face,align,valign,value) {
@ -235,10 +240,55 @@ function createData(x,y,w,h,l,face,align,valign,value) {
canvas.appendChild(newdiv);
canvasObjectIndex++;
}
function createDataTCPDF(x,y,w,h,align,valign,fontname,fontstyle,fontsize,value) {
var canvas=document.getElementById('layoutcanvas');
var newdiv=document.createElement('div');
var dx = Math.round(x * canvasWidth / labelWidth);
var dy = Math.round(y * canvasHeight / labelHeight);
var dw = Math.round(w * canvasWidth / labelWidth);
var dh = Math.round(h * canvasHeight / labelHeight);
var fontheight=(fontsize * 25.4 / 72) * canvasHeight / labelHeight;
var l = Math.floor(h/fontheight);
if(fontheight == 0) fontheight=10;
if(l==0) l=1;
// alert(dh + ", fh="+fontheight);
newdiv.setAttribute('id','o_'+canvasObjectIndex);
newdiv.style.display="table-cell";
newdiv.style.position="absolute";
newdiv.style.width=dw+"px";
newdiv.style.height=dh+"px";
newdiv.style.left=dx+"px";
newdiv.style.top=dy+"px";
newdiv.style.textAlign=align;
newdiv.style.verticalAlign=valign;
newdiv.style.padding="0 0 0 0";
newdiv.style.margin="0 0 0 0";
// newdiv.style.vertical-align=valign;
newdiv.style.border="1px solid blue";
newdiv.style.fontSize=fontheight+"px";
newdiv.style.lineHeight=fontheight+"px";
newdiv.style.fontFamily=fontname;
newdiv.style.fontSizeAdjust=0.65;
var maxlength=Math.floor(dw/(fontheight*0.7))*l;
if(value.length>maxlength) value=value.substring(0,maxlength);
newdiv.innerHTML=value;
canvas.appendChild(newdiv);
canvasObjectIndex++;
}
</script>
<?
@ -394,6 +444,8 @@ function createData(x,y,w,h,l,face,align,valign,value) {
echo "</td></tr>";
echo "</table>\n";
$doCanvasSample = false;
$doCanvasSampletcpdf = false;
$l_w=$report_stock[$report['option']['stock']]['label_width'];
$l_h=$report_stock[$report['option']['stock']]['label_height'];
if($l_w && $l_h && $report['option']['type']=="label") {
@ -405,13 +457,33 @@ function createData(x,y,w,h,l,face,align,valign,value) {
$canvasheight=round($canvaswidth*$ratio);
echo "<div id=\"layoutcanvas\" style=\"border: 1px solid red; position: relative; width: {$canvaswidth}px; height: {$canvasheight}px;\">";
echo "</div>\n";
echo "<script type=\"text/javascript\">initCanvas($canvaswidth,$canvasheight)</script>\n";
echo "<script type=\"text/javascript\">initCanvas($canvaswidth,$canvasheight,$l_w,$l_h)</script>\n";
}
if($l_w && $l_h && $report['option']['type']=="tcpdf_label") {
echo "<h4>Label Data Locations - TCPDF</h4>";
$l_w *= 25.4;
$l_h *= 25.4;
$doCanvasSampletcpdf=true;
$ratio=$l_h/$l_w;
$canvaswidth=600;
$canvasheight=round($canvaswidth*$ratio);
echo "<div id=\"layoutcanvas\" style=\"border: 1px solid red; position: relative; width: {$canvaswidth}px; height: {$canvasheight}px;\">";
echo "</div>\n";
echo "<script type=\"text/javascript\">initCanvas($canvaswidth,$canvasheight,$l_w,$l_h)</script>\n";
}
echo "<table>";
$x=0;
if($report['option']['type'] == 'label') {
if($report['option']['type'] == 'label' || $report['option']['type'] == 'tcpdf_label') {
$fontlist = array('' => 'Default');
$fl = PDF::getFontList();
foreach($fl as $f) $fontlist[$f] = $f;
// print_r($fl);
foreach($report['col'] as $o=>$d) {
$f = $d['field'];
@ -419,17 +491,35 @@ function createData(x,y,w,h,l,face,align,valign,value) {
echo "<td>";
$script="";
foreach($locs as $k=>$v) {
if($k=='Lines' && $report['option']['type'] != 'label') continue;
echo "$k=<input type=\"text\" size=\"3\" name=\"col[$x][$v]\" value=\"{$d[$v]}\">";
$script.="{$d[$v]},";
}
if($report['option']['type'] == 'label') {
echo 'Face=';
selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), $d['face']);
}
echo 'Align';
selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
$d['align']);
echo 'vAlign';
if($report['option']['type'] == 'label') {
selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'),
$d['valign']);
} else {
selector("col[$x][valign]", array('middle' => 'Middle', 'top' => 'Top', 'bottom' => 'Bottom'),
$d['valign']);
echo 'Font=';
selector("col[$x][fontname]", $fontlist, $d['fontname']);
selector("col[$x][fontstyle]", array('' => '', 'bold' => 'Bold'), $d['fontstyle']);
echo "<input type=\"text\" size=\"3\" name=\"col[$x][fontsize]\" value=\"{$d['fontsize']}\">";
echo 'pt ';
echo 'OnOverflow=';
selector("col[$x][on_overflow]", array('tuncate'=>'Truncate','...'=>'Add ...', 'scale'=>'Scale'), $d['on_overflow']);
}
if($f == 'static_text') {
echo "<br />Text=<input type=\"text\" size=\"40\" name=\"col[$x][value]\" value=\"{$d['value']}\">";
} else {
@ -437,6 +527,8 @@ function createData(x,y,w,h,l,face,align,valign,value) {
}
if($doCanvasSample)
echo "<script type=\"text/javascript\">createData({$script}'{$d['face']}','{$d['align']}','{$d['valign']}','{$canvasLabels[$x]}')</script>\n";
if($doCanvasSampletcpdf)
echo "<script type=\"text/javascript\">createDataTCPDF({$script}'{$d['align']}','{$d['valign']}','{$d['fontname']}','{$d['fontstyle']}','{$d['fontsize']}','{$canvasLabels[$x]}')</script>\n";
$x++;
}
@ -444,16 +536,32 @@ function createData(x,y,w,h,l,face,align,valign,value) {
echo "<tr><td align=\"right\">Loc ".($x+1).": </td>";
echo "<td>";
foreach($locs as $k=>$v) {
if($k=='Lines' && $report['option']['type'] != 'label') continue;
echo "$k=<input type=\"text\" size=\"3\" name=\"col[$x][$v]\" value=\"0\">";
}
if($report['option']['type'] == 'label') {
echo 'Face=';
selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), '');
}
echo 'Align';
selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
'center');
echo 'vAlign';
if($report['option']['type'] == 'label') {
selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'),
'top');
} else {
selector("col[$x][valign]", array('middle' => 'Middle', 'top' => 'Top', 'bottom' => 'Bottom'), 'middle');
echo 'Font=';
selector("col[$x][fontname]", $fontlist, '');
selector("col[$x][fontstyle]", array('' => '', 'bold' => 'Bold'), '');
echo "<input type=\"text\" size=\"3\" name=\"col[$x][fontsize]\" value=\"\">";
echo 'pt ';
echo 'OnOverflow=';
selector("col[$x][on_overflow]", array('Truncate'=>'truncate','Add ...'=>'...', 'Scale'=>'scale'),'');
}
echo "<input type=\"hidden\" name=\"col[$x][value]\" value=\"\">";
echo "</td></tr>";
}

View File

@ -1 +1 @@
168
169

8
db/db.update.169.sql Normal file
View File

@ -0,0 +1,8 @@
ALTER TABLE `reports_items` ADD `fontname` VARCHAR( 32 ) NOT NULL AFTER `face` ,
ADD `fontstyle` SET( 'bold', 'italic', 'underline', 'strikethrough') NOT NULL AFTER `fontname` ,
ADD `fontsize` FLOAT NOT NULL AFTER `fontstyle` ;
ALTER TABLE `reports_items` ADD `valign` ENUM( 'top', 'middle', 'bottom' ) NOT NULL;
LTER TABLE `reports_items` ADD `on_overflow` ENUM( 'truncate', '...', 'scale' ) NOT NULL ;

371
tcpdf.inc.php Normal file
View File

@ -0,0 +1,371 @@
<?
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;
function __construct($report_name='', $format='LETTER', $orientation='P')
{
global $config;
/* 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');
$this->SetTitle(i18n($config['fairname']));
$this->SetSubject($report_name);
$this->SetKeywords('');
/* Set default header data (K_PATH_IMAGES/logo.png, 16mm wide,
header, name */
$this->SetHeaderData('logo.png', 16 /* mm */,
i18n($config['fairname']),
i18n($report_name));
// set header and footer fonts
$this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$this->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$this->SetHeaderMargin(PDF_MARGIN_HEADER);
$this->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$this->setPrintFooter(false);
//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;
//set some language-dependent strings
//$this->setLanguageArray($l);
//print_r($this->fontlist);
}
function _fitcell_lines($w,$h,$txt,$fontsize)
{
$index = 0;
$lines = array();
/* Get an array of widths */
$width = $this->getStringWidth($txt,'','',$fontsize,true);
$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();
$fontsize = $orig_fs;
while(1) {
$lines = $this->_fitcell_lines($w, $h, $txt, $fontsize);
$label_h = $this->cMargin * 2 + ($this->getFontSize($fontsize) * count($lines));
// echo "h=$h; fs=".$this->getFontSize($fontsize).", lines=".count($lines).", total=$label_h\n";
if($label_h <= $h) {
/* It fits! */
break;
}
if($on_overflow == 'scale') {
/* reduce the font size and try again */
$fontsize -= 0.5;
$this->setFontSize($fontsize);
// echo "retry...\n";
continue;
} else if($on_overflow == '...') {
/* truncate, add ... */
echo "Not implemented: FitCell::on_overflow=...";
exit;
} else {
/* truncate */
echo "Not implemented: FitCell::on_overflow=truncate";
exit;
}
}
/* SetX, find Y based on alignment */
switch($valign) {
case 'M': /* Middle */
$this->SetXY($x, $y + ($h - $label_h) / 2);
break;
case 'B': /* Bottom */
$this->SetXY($x, $y + ($h - $label_h));
break;
case 'T': default: /* Top */
$this->SetXY($x, $y);
break;
}
/* 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]) */
$this->setFontSize($fontsize);
foreach($lines as $l) {
$this->Cell($w, 0, $l, 0, 2, $align, 0, 0, 0, false);
}
/* Restore original fontsize */
$this->setFontSize($orig_fs);
/* Restore original location */
$this->SetXY($x,$y);
/* Deal with the border and ln, leaving x,y wherever $ln
* tells us to */
$this->Cell($w, $h, '', $border, $ln);
}
function GetFontList()
{
if(!is_object($this)) {
$pdf = new pdf();
return $pdf->GetFontList();
}
$this->getFontsList();
return $this->fontlist;
}
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);
if($this->label_show_logo) {
}
if($this->label_show_fair) {
}
}
function output()
{
$filename=strtolower($this->subject);
$filename=ereg_replace("[^a-z0-9]","_",$filename);
parent::Output($filename.".pdf", "I");
}
/* align = left, center, right
valign = top, middle, bottom,
fontname,
fontstyle,
fontsize,
border = true/false
on_overflow = truncate, ..., scale */
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);
}
}

200
tcpdf_config.php Normal file
View File

@ -0,0 +1,200 @@
<?php
//============================================================+
// File name : tcpdf_config.php
// Begin : 2004-06-11
// Last Update : 2009-09-30
//
// Description : Configuration file for TCPDF.
//
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* Configuration file for TCPDF.
* @author Nicola Asuni
* @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
* @package com.tecnick.tcpdf
* @version 4.0.014
* @link http://tcpdf.sourceforge.net
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @since 2004-10-27
*/
// If you define the constant K_TCPDF_EXTERNAL_CONFIG, the following settings will be ignored.
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
define('K_TCPDF_EXTERNAL_CONFIG',true);
$k_path_main = $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY'].'/';
$k_path_url = $config['SFIABDIRECTORY'].'/';
define ('K_PATH_MAIN', $k_path_main);
define ('K_PATH_URL', $k_path_url);
/**
* path for PDF fonts
* use K_PATH_MAIN.'fonts/old/' for old non-UTF8 fonts
*/
define ('K_PATH_FONTS', K_PATH_MAIN.'tcpdf/fonts/');
/**
* cache directory for temporary files (full path)
*/
define ('K_PATH_CACHE', K_PATH_MAIN.'tcpdf/cache/');
/**
* cache directory for temporary files (url path)
*/
define ('K_PATH_URL_CACHE', K_PATH_URL.'cache/');
/**
*images directory
: */
$sfiab_dir = $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY'];
define ('K_PATH_IMAGES', "$sfiab_dir/data/");
/**
* blank image
*/
define ('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png');
/**
* page format
*/
define ('PDF_PAGE_FORMAT', 'LETTER');
/**
* page orientation (P=portrait, L=landscape)
*/
define ('PDF_PAGE_ORIENTATION', 'P');
/**
* document creator
*/
define ('PDF_CREATOR', 'TCPDF');
/**
* document author
*/
define ('PDF_AUTHOR', 'SFIAB');
/**
* header title
*/
define ('PDF_HEADER_TITLE', $config['fairname']);
/**
* header description string
*/
define ('PDF_HEADER_STRING', "");
/**
* image logo
*/
define ('PDF_HEADER_LOGO', 'logo.png');
/**
* header logo image width [mm]
*/
define ('PDF_HEADER_LOGO_WIDTH', 16);
/**
* document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch]
*/
define ('PDF_UNIT', 'mm');
/**
* header margin
*/
define ('PDF_MARGIN_HEADER', 5);
/**
* footer margin
*/
define ('PDF_MARGIN_FOOTER', 10);
/**
* top margin (includes header height)
*/
define ('PDF_MARGIN_TOP', 40);
/**
* bottom margin
*/
define ('PDF_MARGIN_BOTTOM', 25);
/**
* left margin
*/
define ('PDF_MARGIN_LEFT', 15);
/**
* right margin
*/
define ('PDF_MARGIN_RIGHT', 15);
/**
* default main font name
*/
define ('PDF_FONT_NAME_MAIN', 'helvetica');
/**
* default main font size
*/
define ('PDF_FONT_SIZE_MAIN', 10);
/**
* default data font name
*/
define ('PDF_FONT_NAME_DATA', 'helvetica');
/**
* default data font size
*/
define ('PDF_FONT_SIZE_DATA', 8);
/**
* default monospaced font name
*/
define ('PDF_FONT_MONOSPACED', 'courier');
/**
* ratio used to adjust the conversion of pixels to user units
*/
define ('PDF_IMAGE_SCALE_RATIO', 1);
/**
* magnification factor for titles
*/
define('HEAD_MAGNIFICATION', 1.1);
/**
* height of cell repect font height
*/
define('K_CELL_HEIGHT_RATIO', 1.25);
/**
* title magnification respect main font size
*/
define('K_TITLE_MAGNIFICATION', 1.3);
/**
* reduction factor for small font
*/
define('K_SMALL_RATIO', 2/3);
}
//============================================================+
// END OF FILE
//============================================================+
?>