2include_once (
'class.pdf.php');
4class Cezpdf
extends Cpdf
21 var $ez = array(
'fontSize' => 10);
30 function Cezpdf($paper =
'a4', $orientation =
'portrait')
32 self::__construct($paper, $orientation);
35 function __construct($paper =
'a4', $orientation =
'portrait')
51 if (!is_array($paper))
53 switch (strtoupper($paper))
694 switch (strtolower($orientation))
706 if (count($paper) > 2)
715 $size[2] = ($paper[0] / 2.54) * 72;
716 $size[3] = ($paper[1] / 2.54) * 72;
721 $this->ez[
'pageWidth'] = $size[2];
722 $this->ez[
'pageHeight'] = $size[3];
725 $this->ez[
'topMargin'] = 30;
726 $this->ez[
'bottomMargin'] = 30;
727 $this->ez[
'leftMargin'] = 30;
728 $this->ez[
'rightMargin'] = 30;
731 $this->y = $this->ez[
'pageHeight'] - $this->ez[
'topMargin'];
733 $this->ezPages[1] = $this->getFirstPageId();
734 $this->ezPageCount = 1;
740 function ezSetCmMargins($top, $bottom, $left, $right)
742 $top = ($top / 2.54) * 72;
743 $bottom = ($bottom / 2.54) * 72;
744 $left = ($left / 2.54) * 72;
745 $right = ($right / 2.54) * 72;
746 $this->ezSetMargins($top, $bottom, $left, $right);
750 function ezColumnsStart($options = array(
754 if (isset($this->ez[
'columns']) && $this->ez[
'columns'] == 1)
766 foreach ($def as $k => $v)
768 if (!isset($options[$k]))
775 $this->ez[
'columns'] = array
782 $this->ez[
'columns'][
'margins'] = array
784 $this->ez[
'leftMargin'],
785 $this->ez[
'rightMargin'],
786 $this->ez[
'topMargin'],
787 $this->ez[
'bottomMargin']
791 $this->ez[
'columns'][
'options'] = $options;
794 $this->ez[
'topMargin'] = $this->ez[
'pageHeight'] - $this->y;
795 $width = ($this->ez[
'pageWidth'] - $this->ez[
'leftMargin'] - $this->ez[
'rightMargin'] - ($options[
'num'] - 1)
796 * $options[
'gap']) / $options[
'num'];
797 $this->ez[
'columns'][
'width'] = $width;
798 $this->ez[
'rightMargin'] = $this->ez[
'pageWidth'] - $this->ez[
'leftMargin'] - $width;
802 function ezColumnsStop()
804 if (isset($this->ez[
'columns']) && $this->ez[
'columns'][
'on'] == 1)
806 $this->ez[
'columns'][
'on'] = 0;
807 $this->ez[
'leftMargin'] = $this->ez[
'columns'][
'margins'][0];
808 $this->ez[
'rightMargin'] = $this->ez[
'columns'][
'margins'][1];
809 $this->ez[
'topMargin'] = $this->ez[
'columns'][
'margins'][2];
810 $this->ez[
'bottomMargin'] = $this->ez[
'columns'][
'margins'][3];
815 function ezInsertMode($status = 1, $pageNum = 1, $pos =
'before')
822 if (isset($this->ezPages[$pageNum]))
824 $this->ez[
'insertMode'] = 1;
825 $this->ez[
'insertOptions'] = array
827 'id' => $this->ezPages[$pageNum],
835 $this->ez[
'insertMode'] = 0;
846 if (isset($this->ez[
'columns']) && $this->ez[
'columns'][
'on'] == 1)
851 $this->ez[
'columns'][
'colNum']++;
854 if ($this->ez[
'columns'][
'colNum'] <= $this->ez[
'columns'][
'options'][
'num'])
861 $this->ez[
'columns'][
'colNum'] = 1;
862 $this->ez[
'topMargin'] = $this->ez[
'columns'][
'margins'][2];
865 $width = $this->ez[
'columns'][
'width'];
866 $this->ez[
'leftMargin'] = $this->ez[
'columns'][
'margins'][0] + ($this->ez[
'columns'][
'colNum'] - 1)
867 * ($this->ez[
'columns'][
'options'][
'gap'] + $width);
868 $this->ez[
'rightMargin'] = $this->ez[
'pageWidth'] - $this->ez[
'leftMargin'] - $width;
875 $this->y = $this->ez[
'pageHeight'] - $this->ez[
'topMargin'];
877 $this->ezPageCount++;
879 if (isset($this->ez[
'insertMode']) && $this->ez[
'insertMode'] == 1)
881 $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1, $this->ez[
'insertOptions'][
'id'],
882 $this->ez[
'insertOptions'][
'pos']);
884 $this->ez[
'insertOptions'][
'id'] =
$id;
885 $this->ez[
'insertOptions'][
'pos'] =
'after';
889 $this->ezPages[$this->ezPageCount] = $this->newPage();
894 $this->y = $this->ez[
'pageHeight'] - $this->ez[
'topMargin'];
900 function ezSetMargins($top, $bottom, $left, $right)
903 $this->ez[
'topMargin'] = $top;
904 $this->ez[
'bottomMargin'] = $bottom;
905 $this->ez[
'leftMargin'] = $left;
906 $this->ez[
'rightMargin'] = $right;
910 if ($this->y > $this->ez[
'pageHeight'] - $top)
913 $this->y = $this->ez[
'pageHeight'] - $top;
916 if ($this->y < $bottom)
925 function ezGetCurrentPageNumber()
928 return $this->ezPageCount;
933 function ezStartPageNumbers($x, $y, $size, $pos =
'left', $pattern =
'{PAGENUM} of {TOTALPAGENUM}', $num =
'')
944 if (!$pos || !strlen($pos))
949 if (!$pattern || !strlen($pattern))
951 $pattern =
'{PAGENUM} of {TOTALPAGENUM}';
954 if (!isset($this->ez[
'pageNumbering']))
956 $this->ez[
'pageNumbering'] = array(
960 $i = count($this->ez[
'pageNumbering']);
961 $this->ez[
'pageNumbering'][$i][$this->ezPageCount] = array
966 'pattern' => $pattern,
976 function ezWhatPageNumber($pageNum, $i = 0)
984 if (!isset($this->ez[
'pageNumbering']))
986 $this->addMessage(
'WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
990 foreach ($this->ez[
'pageNumbering'][$i] as $k => $v)
997 if (strlen($v[
'num']))
1002 $num = $pageNum - $startNum + $start;
1018 function ezStopPageNumbers($stopTotal = 0, $next = 0, $i = 0)
1023 if (!isset($this->ez[
'pageNumbering']))
1025 $this->ez[
'pageNumbering'] = array(
1029 if ($next && isset($this->ez[
'pageNumbering'][$i][$this->ezPageCount]) && is_array(
1030 $this->ez[
'pageNumbering'][$i][$this->ezPageCount]))
1036 $this->ez[
'pageNumbering'][$i][$this->ezPageCount][
'stoptn'] = 1;
1040 $this->ez[
'pageNumbering'][$i][$this->ezPageCount][
'stopn'] = 1;
1047 $this->ez[
'pageNumbering'][$i][$this->ezPageCount] =
'stopt';
1051 $this->ez[
'pageNumbering'][$i][$this->ezPageCount] =
'stop';
1056 $this->ez[
'pageNumbering'][$i][$this->ezPageCount] .=
'n';
1063 function ezPRVTpageNumberSearch($lbl, &$tmp)
1065 foreach ($tmp as $i => $v)
1069 if (isset($v[$lbl]))
1088 function ezPRVTaddPageNumbers()
1091 if (isset($this->ez[
'pageNumbering']))
1093 $totalPages1 = $this->ezPageCount;
1094 $tmp1 = $this->ez[
'pageNumbering'];
1097 foreach ($tmp1 as $i => $tmp)
1101 $k = $this->ezPRVTpageNumberSearch(
'stopt', $tmp);
1105 $totalPages = $k - 1;
1109 $l = $this->ezPRVTpageNumberSearch(
'stoptn', $tmp);
1117 $totalPages = $totalPages1;
1121 foreach ($this->ezPages as $pageNum =>
$id)
1123 if (isset($tmp[$pageNum]))
1125 if (is_array($tmp[$pageNum]))
1129 $info = $tmp[$pageNum];
1130 $info[
'dnum'] = $info[
'num'] - $pageNum;
1133 if (isset($info[
'stopn']) || isset($info[
'stoptn']))
1138 else if ($tmp[$pageNum] ==
'stop' || $tmp[$pageNum] ==
'stopt')
1143 else if ($status == 1 && ($tmp[$pageNum] ==
'stoptn' || $tmp[$pageNum] ==
'stopn'))
1153 if (strlen($info[
'num']))
1155 $num = $pageNum + $info[
'dnum'];
1162 $total = $totalPages + $num - $pageNum;
1163 $pat = str_replace(
'{PAGENUM}', $num, $info[
'pattern']);
1164 $pat = str_replace(
'{TOTALPAGENUM}', $total, $pat);
1165 $this->reopenObject(
$id);
1167 switch ($info[
'pos'])
1170 $this->addText($info[
'x'], $info[
'y'], $info[
'size'], $pat);
1175 $w = $this->getTextWidth($info[
'size'], $pat);
1177 $this->addText($info[
'x'] - $w, $info[
'y'], $info[
'size'], $pat);
1181 $this->closeObject();
1195 function ezPRVTcleanUp()
1197 $this->ezPRVTaddPageNumbers();
1202 function ezStream($options =
'')
1204 $this->ezPRVTcleanUp();
1205 $this->stream($options);
1210 function ezOutput($options = 0)
1212 $this->ezPRVTcleanUp();
1213 return $this->output($options);
1223 if ($this->y < $this->ez[
'bottomMargin'])
1232 function ezSetDy($dy, $mod =
'')
1241 if ($this->y < $this->ez[
'bottomMargin'])
1246 if ($mod ==
'makeSpace')
1255 function ezPrvtTableDrawLines($pos, $gap, $x0, $x1, $y0, $y1, $y2, $col, $inner, $outer, $opt = 1)
1259 $this->setStrokeColor($col[0], $col[1], $col[2]);
1263 foreach ($pos as $x)
1267 if ($cnt == 1 || $cnt == $n)
1269 $this->setLineStyle($outer);
1273 $this->setLineStyle($inner);
1276 $this->line($x - $gap / 2, $y0, $x - $gap / 2, $y2);
1293 $this->setLineStyle($outer);
1294 $this->line($x0 - $gap / 2 - $outer / 2, $y0, $x1 - $gap / 2 + $outer / 2, $y0);
1298 if ($y0 != $y1 && $opt < 2)
1300 $this->line($x0 - $gap / 2, $y1, $x1 - $gap / 2, $y1);
1303 $this->line($x0 - $gap / 2 - $outer / 2, $y2, $x1 - $gap / 2 + $outer / 2, $y2);
1308 function ezPrvtTableColumnHeadings($cols, $pos, $maxWidth, $height, $decender, $gap, $size, &$y,
1309 $optionsAll = array(
1316 if (isset($optionsAll[
'cols']))
1318 $options = $optionsAll[
'cols'];
1327 $startPage = $this->ezPageCount;
1337 $this->transaction(
'start');
1344 foreach ($cols as $colName => $colHeading)
1348 if (isset($options[$colName]) && isset($options[$colName][
'justification']))
1350 $justification = $options[$colName][
'justification'];
1354 $justification =
'left';
1357 $this->ezText($colHeading,
1359 array(
'aleft' => $pos[$colName],
'aright' => ($maxWidth[$colName] + $pos[$colName]),
1360 'justification' => $justification));
1361 $dy = $y - $this->y;
1369 $y = $y - $mx - $gap + $decender;
1375 if ($this->ezPageCount != $startPage && $secondGo == 0)
1377 $this->transaction(
'rewind');
1379 $y = $this->y - $gap - $decender;
1387 $this->transaction(
'commit');
1392 return $mx + $gap * 2 - $decender;
1397 function ezPrvtGetTextWidth($size, $text)
1402 $lines = explode(
"\n", $text);
1404 foreach ($lines as $line)
1406 $w = $this->getTextWidth($size, $line);
1419 function ezTable(&$data, $cols =
'',
$title =
'', $options =
'')
1458 if (!is_array($data))
1463 if (!is_array($cols))
1467 list($k, $v) = each($data);
1477 foreach ($v as $k1 => $v1)
1483 if (!is_array($options))
1493 'shadeCol' => array(0.8, 0.8, 0.8),
1494 'shadeCol2' => array(0.7, 0.7, 0.7),
1496 'titleFontSize' => 12,
1498 'lineCol' => array(0, 0, 0),
1501 'xOrientation' =>
'centre',
1502 'showHeadings' => 1,
1503 'textCol' => array(0, 0, 0),
1508 'minRowSpace' => -100,
1511 'innerLineThickness' => 1,
1512 'outerLineThickness' => 1,
1517 foreach ($defaults as $key => $value)
1519 if (is_array($value))
1521 if (!isset($options[$key]) || !is_array($options[$key]))
1523 $options[$key] = $value;
1528 if (!isset($options[$key]))
1530 $options[$key] = $value;
1535 $options[
'gap'] = 2 * $options[
'colGap'];
1537 $middle = ($this->ez[
'pageWidth'] - $this->ez[
'rightMargin']) / 2 + ($this->ez[
'leftMargin']) / 2;
1542 foreach ($cols as $colName => $colHeading)
1544 $maxWidth[$colName] = 0;
1548 foreach ($data as $row)
1550 foreach ($cols as $colName => $colHeading)
1552 $w = $this->ezPrvtGetTextWidth($options[
'fontSize'], (
string)$row[$colName]) * 1.01;
1554 if ($w > $maxWidth[$colName])
1556 $maxWidth[$colName] = $w;
1562 foreach ($cols as $colName => $colTitle)
1564 $w = $this->ezPrvtGetTextWidth($options[
'fontSize'], (
string)$colTitle) * 1.01;
1566 if ($w > $maxWidth[$colName])
1568 $maxWidth[$colName] = $w;
1578 $adjustmentWidth = 0;
1581 foreach ($maxWidth as $colName => $w)
1583 $pos[$colName] = $t;
1587 if (isset($options[
'cols'][$colName]) && isset($options[
'cols'][$colName][
'width'])
1588 && $options[
'cols'][$colName][
'width'] > 0)
1590 $t = $t + $options[
'cols'][$colName][
'width'];
1591 $maxWidth[$colName] = $options[
'cols'][$colName][
'width'] - $options[
'gap'];
1592 $setWidth += $options[
'cols'][$colName][
'width'];
1596 $t = $t + $w + $options[
'gap'];
1597 $adjustmentWidth += $w;
1598 $setWidth += $options[
'gap'];
1606 if ($options[
'width'] == 0 && $options[
'maxWidth'] && ($t - $x) > $options[
'maxWidth'])
1609 $options[
'width'] = $options[
'maxWidth'];
1612 if ($options[
'width'] && $adjustmentWidth > 0 && $setWidth < $options[
'width'])
1625 foreach ($pos as $colName => $p)
1627 if (!isset($options[
'cols'][$last]) || !isset($options[
'cols'][$last][
'width'])
1628 || $options[
'cols'][$last][
'width'] <= 0)
1632 $cols0[$last] = $p - $xq - $options[
'gap'];
1633 $presentWidth += ($p - $xq - $options[
'gap']);
1638 $cols1[$last] = $p - $xq;
1646 $neededWidth = $options[
'width'] - $setWidth;
1649 if ($presentWidth < $neededWidth)
1651 foreach ($cols0 as $colName => $w)
1653 $cols0[$colName] += ($neededWidth - $presentWidth) / count($cols0);
1660 while ($presentWidth > $neededWidth && $cnt < 100)
1670 foreach ($cols0 as $colName => $w)
1674 $aWidest = array($colName);
1678 else if ($w == $widest)
1680 $aWidest[] = $colName;
1685 $newWidestWidth = $widest - ($presentWidth - $neededWidth) / count($aWidest);
1687 if ($newWidestWidth > $nWidest)
1690 foreach ($aWidest as $colName)
1692 $cols0[$colName] = $newWidestWidth;
1695 $presentWidth = $neededWidth;
1701 foreach ($aWidest as $colName)
1703 $cols0[$colName] = $nWidest;
1706 $presentWidth = $presentWidth - ($widest - $nWidest) * count($aWidest);
1715 foreach ($pos as $colName => $p)
1717 $pos[$colName] = $xq;
1719 if (!isset($options[
'cols'][$colName]) || !isset($options[
'cols'][$colName][
'width'])
1720 || $options[
'cols'][$colName][
'width'] <= 0)
1722 if (isset($cols0[$colName]))
1724 $xq += $cols0[$colName] + $options[
'gap'];
1725 $maxWidth[$colName] = $cols0[$colName];
1730 if (isset($cols1[$colName]))
1732 $xq += $cols1[$colName];
1737 $t = $x + $options[
'width'];
1742 switch ($options[
'xPos'])
1745 $xref = $this->ez[
'leftMargin'];
1750 $xref = $this->ez[
'pageWidth'] - $this->ez[
'rightMargin'];
1761 $xref = $options[
'xPos'];
1766 switch ($options[
'xOrientation'])
1780 $dx = $xref - $t / 2;
1785 foreach ($pos as $k => $v)
1787 $pos[$k] = $v + $dx;
1793 $baseLeftMargin = $this->ez[
'leftMargin'];
1799 $this->setColor($options[
'textCol'][0], $options[
'textCol'][1], $options[
'textCol'][2]);
1800 $this->setStrokeColor($options[
'shadeCol'][0], $options[
'shadeCol'][1], $options[
'shadeCol'][2]);
1802 $middle = ($x1 + $x0) / 2;
1805 if ($options[
'protectRows'] > 0)
1807 $this->transaction(
'start');
1817 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
1819 foreach ($basePos as $k => $v)
1821 $pos[$k] = $v + $dm;
1824 $x0 = $baseX0 + $dm;
1825 $x1 = $baseX1 + $dm;
1826 $middle = ($x1 + $x0) / 2;
1831 $w = $this->getTextWidth($options[
'titleFontSize'],
$title);
1832 $this->y -= $this->getFontHeight($options[
'titleFontSize']);
1834 if ($this->y < $this->ez[
'bottomMargin'])
1838 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
1840 foreach ($basePos as $k => $v)
1842 $pos[$k] = $v + $dm;
1845 $x0 = $baseX0 + $dm;
1846 $x1 = $baseX1 + $dm;
1847 $middle = ($x1 + $x0) / 2;
1848 $this->y -= $this->getFontHeight($options[
'titleFontSize']);
1851 $this->addText($middle - $w / 2, $this->y, $options[
'titleFontSize'],
$title);
1852 $this->y -= $options[
'titleGap'];
1856 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
1858 foreach ($basePos as $k => $v)
1860 $pos[$k] = $v + $dm;
1863 $x0 = $baseX0 + $dm;
1864 $x1 = $baseX1 + $dm;
1869 $height = $this->getFontHeight($options[
'fontSize']);
1870 $decender = $this->getFontDecender($options[
'fontSize']);
1872 $y0 = $y + $decender;
1875 if ($options[
'showHeadings'])
1877 if ($options[
'shaded'])
1880 $textObjectId = $this->openObject();
1884 $headingHeight = $this->ezPrvtTableColumnHeadings(
1885 $cols, $pos, $maxWidth, $height, $decender, $options[
'rowGap'],
1886 $options[
'fontSize'], $y, $options);
1887 $y0 = $y + $headingHeight;
1890 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
1892 foreach ($basePos as $k => $v)
1894 $pos[$k] = $v + $dm;
1897 $x0 = $baseX0 + $dm;
1898 $x1 = $baseX1 + $dm;
1900 if ($options[
'shaded'])
1902 $this->closeObject();
1903 $this->setColor($options[
'shadeCol'][0], $options[
'shadeCol'][1], $options[
'shadeCol'][2], 1);
1904 $this->filledRectangle($x0 - $options[
'gap'] / 2, $y1, $x1 - $x0, $headingHeight);
1905 $this->addObject($textObjectId);
1906 $this->closeObject();
1907 $this->restoreState();
1918 if ($options[
'shaded'])
1921 $textObjectId = $this->openObject();
1922 $this->closeObject();
1932 $this->addObject($textObjectId);
1937 $this->reopenObject($textObjectId);
1943 foreach ($data as $row)
1948 if ($options[
'splitRows'] == 0)
1950 $pageStart = $this->ezPageCount;
1952 if (isset($this->ez[
'columns']) && $this->ez[
'columns'][
'on'] == 1)
1954 $columnStart = $this->ez[
'columns'][
'colNum'];
1957 $this->transaction(
'start');
1967 while (!$abortTable && $ok == 0)
1972 while (!$abortTable && ($newPage || $newRow))
1976 if ($newPage || $y < $this->ez[
'bottomMargin'] || (isset($options[
'minRowSpace']) && $y
1977 < ($this->ez[
'bottomMargin']
1978 + $options[
'minRowSpace'])))
1981 if ($options[
'protectRows'] > 0 && $movedOnce == 0 && $cnt <= $options[
'protectRows'])
1988 $y2 = $y - $mx + 2 * $height + $decender - $newRow * $height;
1990 if ($options[
'showLines'])
1992 if (!$options[
'showHeadings'])
1997 $this->ezPrvtTableDrawLines($pos,
2004 $options[
'lineCol'],
2005 $options[
'innerLineThickness'],
2006 $options[
'outerLineThickness'],
2007 $options[
'showLines']);
2010 if ($options[
'shaded'])
2012 $this->closeObject();
2013 $this->restoreState();
2020 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
2022 foreach ($basePos as $k => $v)
2024 $pos[$k] = $v + $dm;
2029 $x0 = $baseX0 + $dm;
2030 $x1 = $baseX1 + $dm;
2032 if ($options[
'shaded'])
2035 $textObjectId = $this->openObject();
2036 $this->closeObject();
2037 $this->addObject($textObjectId);
2038 $this->reopenObject($textObjectId);
2041 $this->setColor($options[
'textCol'][0], $options[
'textCol'][1], $options[
'textCol'][2], 1);
2042 $y = $this->ez[
'pageHeight'] - $this->ez[
'topMargin'];
2043 $y0 = $y + $decender;
2046 if ($options[
'showHeadings'])
2048 $this->ezPrvtTableColumnHeadings(
2049 $cols, $pos, $maxWidth, $height, $decender, $options[
'rowGap'],
2050 $options[
'fontSize'], $y, $options);
2070 foreach ($cols as $colName => $colTitle)
2072 $this->ezSetY($y + $height);
2075 if (isset($row[$colName]))
2077 if (isset($options[
'cols'][$colName]) && isset($options[
'cols'][$colName][
'link'])
2078 && strlen($options[
'cols'][$colName][
'link']))
2080 $lines = explode(
"\n", $row[$colName]);
2082 if (isset($row[$options[
'cols'][$colName][
'link']])
2083 && strlen($row[$options[
'cols'][$colName][
'link']]))
2085 foreach ($lines as $k => $v)
2088 =
'<c:alink:' . $row[$options[
'cols'][$colName][
'link']] .
'>' . $v
2095 $lines = explode(
"\n", $row[$colName]);
2104 $this->y -= $options[
'rowGap'];
2106 foreach ($lines as $line)
2108 $line = $this->ezProcessText($line);
2111 while (strlen($line) || $start)
2117 $this->y = $this->y - $height;
2120 if ($this->y < $this->ez[
'bottomMargin'])
2129 if (isset($leftOvers[$colName]))
2131 $leftOvers[$colName] .=
"\n" . $line;
2135 $leftOvers[$colName] = $line;
2142 if (isset($options[
'cols'][$colName]) && isset(
2143 $options[
'cols'][$colName][
'justification']))
2145 $just = $options[
'cols'][$colName][
'justification'];
2152 $line = $this->addTextWrap(
2153 $pos[$colName], $this->y, $maxWidth[$colName], $options[
'fontSize'],
2159 $dy = $y + $height - $this->y + $options[
'rowGap'];
2161 if ($dy - $height * $newPage > $mx)
2163 $mx = $dy - $height * $newPage;
2171 if ($options[
'shaded'] && $cnt % 2 == 0)
2173 $this->closeObject();
2174 $this->setColor($options[
'shadeCol'][0], $options[
'shadeCol'][1], $options[
'shadeCol'][2],
2176 $this->filledRectangle($x0 - $options[
'gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
2178 $this->reopenObject($textObjectId);
2181 if ($options[
'shaded'] == 2 && $cnt % 2 == 1)
2183 $this->closeObject();
2184 $this->setColor($options[
'shadeCol2'][0], $options[
'shadeCol2'][1],
2185 $options[
'shadeCol2'][2], 1);
2186 $this->filledRectangle($x0 - $options[
'gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
2188 $this->reopenObject($textObjectId);
2191 if ($options[
'showLines'] > 1)
2196 $this->setStrokeColor($options[
'lineCol'][0], $options[
'lineCol'][1],
2197 $options[
'lineCol'][2], 1);
2202 $this->setLineStyle($options[
'outerLineThickness']);
2207 $this->setLineStyle($options[
'innerLineThickness']);
2210 $this->line($x0 - $options[
'gap'] / 2, $y + $decender + $height, $x1 - $options[
'gap'] / 2,
2211 $y + $decender + $height);
2212 $this->restoreState();
2217 $y = $y - $mx + $height;
2220 if ($options[
'splitRows'] == 0)
2222 if ((($this->ezPageCount != $pageStart) || (isset($this->ez[
'columns'])
2223 && $this->ez[
'columns'][
'on'] == 1
2225 != $this->ez[
'columns'][
'colNum']))
2226 && $secondTurn == 0)
2231 $this->transaction(
'rewind');
2238 $dm = $this->ez[
'leftMargin'] - $baseLeftMargin;
2240 foreach ($basePos as $k => $v)
2242 $pos[$k] = $v + $dm;
2245 $x0 = $baseX0 + $dm;
2246 $x1 = $baseX1 + $dm;
2250 $this->transaction(
'commit');
2264 $this->transaction(
'abort');
2268 $this->transaction(
'rewind');
2276 $this->transaction(
'commit');
2278 $y2 = $y + $decender;
2280 if ($options[
'showLines'])
2282 if (!$options[
'showHeadings'])
2287 $this->ezPrvtTableDrawLines($pos, $options[
'gap'],
2290 $y2, $options[
'lineCol'],
2291 $options[
'innerLineThickness'], $options[
'outerLineThickness'],
2292 $options[
'showLines']);
2296 if ($options[
'shaded'])
2298 $this->closeObject();
2299 $this->restoreState();
2307 function ezProcessText($text)
2327 return str_replace($search, $replace, $text);
2332 function ezText($text, $size = 0, $options = array(
2355 $text = $this->ezProcessText($text);
2358 $store_y = $this->y;
2360 if (is_array($options) && isset($options[
'aleft']))
2362 $left = $options[
'aleft'];
2366 $left = $this->ez[
'leftMargin'] + ((is_array($options) && isset($options[
'left'])) ? $options[
'left'] : 0);
2369 if (is_array($options) && isset($options[
'aright']))
2371 $right = $options[
'aright'];
2375 $right = $this->ez[
'pageWidth'] - $this->ez[
'rightMargin'] - ((is_array(
2376 $options) && isset($options[
'right']))
2377 ? $options[
'right'] : 0);
2382 $size = $this->ez[
'fontSize'];
2386 $this->ez[
'fontSize'] = $size;
2389 if (is_array($options) && isset($options[
'justification']))
2391 $just = $options[
'justification'];
2399 if (is_array($options) && isset($options[
'leading']))
2400 { ## use leading instead of spacing
2401 $height = $options[
'leading'];
2403 else if (is_array($options) && isset($options[
'spacing']))
2405 $height = $this->getFontHeight($size) * $options[
'spacing'];
2409 $height = $this->getFontHeight($size);
2412 $lines = explode(
"\n", $text);
2414 foreach ($lines as $line)
2418 while (strlen($line) || $start)
2421 $this->y = $this->y - $height;
2423 if ($this->y < $this->ez[
'bottomMargin'])
2436 if (is_array($options) && isset($options[
'aleft']))
2438 $left = $options[
'aleft'];
2442 $left = $this->ez[
'leftMargin'] + ((is_array(
2444 $options[
'left'])) ? $options[
'left'] : 0);
2447 if (is_array($options) && isset($options[
'aright']))
2449 $right = $options[
'aright'];
2453 $right = $this->ez[
'pageWidth'] - $this->ez[
'rightMargin'] - ((is_array($options)
2454 && isset($options[
'right']))
2455 ? $options[
'right'] : 0);
2458 $line = $this->addTextWrap($left, $this->y, $right - $left, $size, $line, $just, 0, $test);
2464 $this->y = $store_y;
2475 function ezImage($image, $pad = 5, $width = 0, $resize =
'full', $just =
'center', $border =
'')
2478 if (stristr($image,
'://'))
2480 $fp = @fopen($image,
"rb");
2484 $cont .= fread($fp, 1024);
2488 $image = tempnam(
"/tmp",
"php-pdf");
2489 $fp2 = @fopen($image,
"w");
2490 fwrite($fp2, $cont);
2495 if (!(file_exists($image)))
2498 $imageInfo = getimagesize($image);
2500 switch ($imageInfo[2])
2512 default:
return false;
2516 $width = $imageInfo[0];
2518 $ratio = $imageInfo[0] / $imageInfo[1];
2521 if (isset($this->ez[
'columns']) && $this->ez[
'columns'][
'on'] == 1)
2523 $bigwidth = $this->ez[
'columns'][
'width'] - ($pad * 2);
2527 $bigwidth = $this->ez[
'pageWidth'] - ($pad * 2);
2531 if ($resize ==
'full' || $resize ==
'width' || $width > $bigwidth)
2536 $height = ($width / $ratio);
2539 if ($height > ($this->y - $this->ez[
'bottomMargin'] - ($pad * 2)))
2541 if ($resize !=
'full')
2547 $height = ($this->y - $this->ez[
'bottomMargin'] - ($pad * 2));
2548 $width = ($height * $ratio);
2553 if ($width < $bigwidth)
2556 if ($just ==
'center')
2558 $offset = ($bigwidth - $width) / 2;
2562 if ($just ==
'right')
2564 $offset = ($bigwidth - $width);
2568 if ($just ==
'left')
2575 if ($type ==
"jpeg")
2577 $this->addJpegFromFile($image,
2578 $this->ez[
'leftMargin'] + $pad + $offset,
2579 $this->y + $this->getFontHeight($this->ez[
'fontSize']) - $pad - $height,
2585 $this->addPngFromFile($image,
2586 $this->ez[
'leftMargin'] + $pad + $offset,
2587 $this->y + $this->getFontHeight($this->ez[
'fontSize']) - $pad - $height,
2594 if (!(isset($border[
'color'])))
2596 $border[
'color'][
'red'] = .5;
2597 $border[
'color'][
'blue'] = .5;
2598 $border[
'color'][
'green'] = .5;
2601 if (!(isset($border[
'width'])))
2602 $border[
'width'] = 1;
2604 if (!(isset($border[
'cap'])))
2605 $border[
'cap'] =
'round';
2607 if (!(isset($border[
'join'])))
2608 $border[
'join'] =
'round';
2610 $this->setStrokeColor($border[
'color'][
'red'], $border[
'color'][
'green'], $border[
'color'][
'blue']);
2611 $this->setLineStyle($border[
'width'], $border[
'cap'], $border[
'join']);
2612 $this->rectangle($this->ez[
'leftMargin'] + $pad + $offset,
2613 $this->y + $this->getFontHeight($this->ez[
'fontSize']) - $pad - $height,
2619 $this->y = $this->y - $pad - $height;
2630 function loadTemplate($templateFile)
2636 if (!file_exists($templateFile))
2641 $code = implode(
'', file($templateFile));
2648 $code = trim($code);
2650 if (substr($code, 0, 5) ==
'<?php')
2652 $code = substr($code, 5);
2655 if (substr($code, -2) ==
'?>')
2657 $code = substr($code, 0, strlen($code) - 2);
2660 if (isset($this->ez[
'numTemplates']))
2662 $newNum = $this->ez[
'numTemplates'];
2663 $this->ez[
'numTemplates']++;
2668 $this->ez[
'numTemplates'] = 1;
2669 $this->ez[
'templates'] = array(
2673 $this->ez[
'templates'][$newNum][
'code'] = $code;
2680 function execTemplate(
$id, $data = array(
2681 ), $options = array(
2685 if (!isset($this->ez[
'templates'][
$id]))
2690 eval ($this->ez[
'templates'][
$id][
'code']);
2694 function ilink($info)
2696 $this->alink($info, 1);
2699 function alink($info, $internal = 0)
2704 switch ($info[
'status'])
2710 if (!isset($this->ez[
'links']))
2712 $this->ez[
'links'] = array(
2716 $i = $info[
'nCallback'];
2717 $this->ez[
'links'][$i] = array
2721 'angle' => $info[
'angle'],
2722 'decender' => $info[
'decender'],
2723 'height' => $info[
'height'],
2730 $this->setColor(0, 0, 1);
2731 $this->setStrokeColor(0, 0, 1);
2732 $thick = $info[
'height'] * $lineFactor;
2733 $this->setLineStyle($thick);
2742 $i = $info[
'nCallback'];
2744 $start = $this->ez[
'links'][$i];
2749 $this->addInternalLink($start[
'url'], $start[
'x'], $start[
'y'] + $start[
'decender'], $info[
'x'],
2750 $start[
'y'] + $start[
'decender'] + $start[
'height']);
2754 $a = deg2rad((
float)$start[
'angle'] - 90.0);
2755 $drop = $start[
'height'] * $lineFactor * 1.5;
2756 $dropx = cos($a) * $drop;
2757 $dropy = -sin($a) * $drop;
2758 $this->line($start[
'x'] - $dropx, $start[
'y'] - $dropy, $info[
'x'] - $dropx, $info[
'y'] - $dropy);
2759 $this->addLink($start[
'url'], $start[
'x'], $start[
'y'] + $start[
'decender'], $info[
'x'],
2760 $start[
'y'] + $start[
'decender'] + $start[
'height']);
2761 $this->restoreState();
2770 function uline($info)
2775 switch ($info[
'status'])
2781 if (!isset($this->ez[
'links']))
2783 $this->ez[
'links'] = array(
2787 $i = $info[
'nCallback'];
2788 $this->ez[
'links'][$i] = array
2792 'angle' => $info[
'angle'],
2793 'decender' => $info[
'decender'],
2794 'height' => $info[
'height']
2798 $thick = $info[
'height'] * $lineFactor;
2799 $this->setLineStyle($thick);
2806 $i = $info[
'nCallback'];
2808 $start = $this->ez[
'links'][$i];
2810 $a = deg2rad((
float)$start[
'angle'] - 90.0);
2811 $drop = $start[
'height'] * $lineFactor * 1.5;
2812 $dropx = cos($a) * $drop;
2813 $dropy = -sin($a) * $drop;
2814 $this->line($start[
'x'] - $dropx, $start[
'y'] - $dropy, $info[
'x'] - $dropx, $info[
'y'] - $dropy);
2815 $this->restoreState();