* TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).
*
* class PDF extends TCPDF { * function Footer() { * //Go to 1.5 cm from bottom * $this->SetY(-15); * //Select Arial italic 8 * $this->SetFont('Arial','I',8); * //Print current and total page numbers * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); * } * } * $pdf=new PDF(); * $pdf->AliasNbPages(); ** @param string $alias The alias. Default value: {nb}. * @since 1.4 * @see PageNo(), Footer() */ function AliasNbPages($alias='{nb}') { //Define an alias for total number of pages $this->AliasNbPages = $this->_escapetext($alias); } /** * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong * @param string $msg The error message * @since 1.0 */ function Error($msg) { //Fatal error die('TCPDF error: '.$msg); } /** * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically. * Note: no page is created by this method * @since 1.0 * @see AddPage(), Close() */ function Open() { //Begin document $this->state=1; } /** * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document. * @since 1.0 * @see Open(), Output() */ function Close() { //Terminate document if($this->state==3) { return; } if($this->page==0) { $this->AddPage(); } //Page footer $this->InFooter=true; $this->Footer(); $this->InFooter=false; //Close page $this->_endpage(); //Close document $this->_enddoc(); } /** * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header. * The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards. * @param string $orientation Page orientation. Possible values are (case insensitive):
* $pdf->AddFont('Comic','I'); * // is equivalent to: * $pdf->AddFont('Comic','I','comici.php'); ** @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. * @param string $style Font style. Possible values are (case insensitive):
* define('FPDF_FONTPATH','/home/www/font/'); * require('tcpdf.php'); * * //Times regular 12 * $pdf->SetFont('Times'); * //Arial bold 14 * $pdf->SetFont('Arial','B',14); * //Removes bold * $pdf->SetFont(''); * //Times bold, italic and underlined 14 * $pdf->SetFont('Times','BIU'); *
* class PDF extends TCPDF { * var $col=0; * * function SetCol($col) { * //Move position to a column * $this->col=$col; * $x=10+$col*65; * $this->SetLeftMargin($x); * $this->SetX($x); * } * * function AcceptPageBreak() { * if($this->col<2) { * //Go to next column * $this->SetCol($this->col+1); * $this->SetY(10); * return false; * } * else { * //Go back to first column and issue page break * $this->SetCol(0); * return true; * } * } * } * * $pdf=new PDF(); * $pdf->Open(); * $pdf->AddPage(); * $pdf->SetFont('Arial','',12); * for($i=1;$i<=300;$i++) { * $pdf->Cell(0,5,"Line $i",0,1); * } * $pdf->Output(); ** @return boolean * @since 1.4 * @see SetAutoPageBreak() */ function AcceptPageBreak() { //Accept automatic page break or not return $this->AutoPageBreak; } /** * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.
* //Begin with regular font * $pdf->SetFont('Arial','',14); * $pdf->Write(5,'Visit '); * //Then put a blue underlined link * $pdf->SetTextColor(0,0,255); * $pdf->SetFont('','U'); * $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com'); ** @param float $h Line height * @param string $txt String to print * @param mixed $link URL or identifier returned by AddLink() * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0. * @since 1.5 * @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak() */ function Write($h, $txt, $link='', $fill=0) { //Output text in flowing mode $cw = &$this->CurrentFont['cw']; $w = $this->w - $this->rMargin - $this->x; $wmax = ($w - 2 * $this->cMargin); $s = str_replace("\r", '', $txt); $nb = strlen($s); // handle single space character if(($nb==1) AND preg_match("/[ ]/u", $s)) { $this->x += $this->GetStringWidth($s); return; } $sep=-1; $i=0; $j=0; $l=0; $nl=1; while($i<$nb) { //Get next character $c=$s{$i}; if(preg_match("/[\n]/u", $c)) { //Explicit line break $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link); $i++; $sep = -1; $j = $i; $l = 0; if($nl == 1) { $this->x = $this->lMargin; $w = $this->w - $this->rMargin - $this->x; $wmax = ($w - 2 * $this->cMargin); } $nl++; continue; } if(preg_match("/[ ]/u", $c)) { $sep= $i; } $l = $this->GetStringWidth(substr($s, $j, $i-$j)); if($l > $wmax) { //Automatic line break (word wrapping) if($sep == -1) { if($this->x > $this->lMargin) { //Move to next line $this->x = $this->lMargin; $this->y += $h; $w=$this->w - $this->rMargin - $this->x; $wmax=($w - 2 * $this->cMargin); $i++; $nl++; continue; } if($i==$j) { $i++; } $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link); } else { $this->Cell($w, $h, substr($s, $j, $sep-$j), 0, 2, '', $fill, $link); $i=$sep+1; } $sep = -1; $j = $i; $l = 0; if($nl==1) { $this->x = $this->lMargin; $w = $this->w - $this->rMargin - $this->x; $wmax = ($w - 2 * $this->cMargin); } $nl++; } else { $i++; } } //Last chunk if($i!=$j) { $this->Cell($this->GetStringWidth(substr($s, $j)), $h, substr($s, $j), 0, 0, '', $fill, $link); } } /** * Puts an image in the page. The upper-left corner must be given. The dimensions can be specified in different ways:
* Char. number range | UTF-8 octet sequence * (hexadecimal) | (binary) * --------------------+----------------------------------------------- * 0000 0000-0000 007F | 0xxxxxxx * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx * --------------------------------------------------------------------- * * ABFN notation: * --------------------------------------------------------------------- * UTF8-octets = *( UTF8-char ) * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4 * UTF8-1 = %x00-7F * UTF8-2 = %xC2-DF UTF8-tail * * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) / * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail ) * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) / * %xF4 %x80-8F 2( UTF8-tail ) * UTF8-tail = %x80-BF * --------------------------------------------------------------------- ** @param string $str string to process. * @return array containing codepoints (UTF-8 characters values) * @access protected * @author Nicola Asuni * @since 1.53.0.TC005 (2005-01-05) */ function UTF8StringToArray($str) { if(!$this->isunicode) { return $str; // string is not in unicode } $unicode = array(); // array containing unicode values $bytes = array(); // array containing single character byte sequences $numbytes = 1; // number of octetc needed to represent the UTF-8 character $str .= ""; // force $str to be a string $length = strlen($str); for($i = 0; $i < $length; $i++) { $char = ord($str{$i}); // get one string character at time if(count($bytes) == 0) { // get starting octect if ($char <= 0x7F) { $unicode[] = $char; // use the character "as is" because is ASCII $numbytes = 1; } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN) $bytes[] = ($char - 0xC0) << 0x06; $numbytes = 2; } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN) $bytes[] = ($char - 0xE0) << 0x0C; $numbytes = 3; } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN) $bytes[] = ($char - 0xF0) << 0x12; $numbytes = 4; } else { // use replacement character for other invalid sequences $unicode[] = 0xFFFD; $bytes = array(); $numbytes = 1; } } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN $bytes[] = $char - 0x80; if (count($bytes) == $numbytes) { // compose UTF-8 bytes to a single unicode value $char = $bytes[0]; for($j = 1; $j < $numbytes; $j++) { $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06)); } if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) { /* The definition of UTF-8 prohibits encoding character numbers between U+D800 and U+DFFF, which are reserved for use with the UTF-16 encoding form (as surrogate pairs) and do not directly represent characters. */ $unicode[] = 0xFFFD; // use replacement character } else { $unicode[] = $char; // add char to array } // reset data for next char $bytes = array(); $numbytes = 1; } } else { // use replacement character for other invalid sequences $unicode[] = 0xFFFD; $bytes = array(); $numbytes = 1; } } return $unicode; } /** * Converts UTF-8 strings to UTF16-BE.
* Encoding UTF-16: * * Encoding of a single character from an ISO 10646 character value to * UTF-16 proceeds as follows. Let U be the character number, no greater * than 0x10FFFF. * * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and * terminate. * * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF, * U' must be less than or equal to 0xFFFFF. That is, U' can be * represented in 20 bits. * * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and * 0xDC00, respectively. These integers each have 10 bits free to * encode the character value, for a total of 20 bits. * * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order * bits of W1 and the 10 low-order bits of U' to the 10 low-order * bits of W2. Terminate. * * Graphically, steps 2 through 4 look like: * U' = yyyyyyyyyyxxxxxxxxxx * W1 = 110110yyyyyyyyyy * W2 = 110111xxxxxxxxxx ** @param string $str string to process. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF) * @return string * @access protected * @author Nicola Asuni * @since 1.53.0.TC005 (2005-01-05) * @uses UTF8StringToArray */ function UTF8ToUTF16BE($str, $setbom=true) { if(!$this->isunicode) { return $str; // string is not in unicode } $outstr = ""; // string to be returned $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values $numitems = count($unicode); if ($setbom) { $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) } foreach($unicode as $char) { if($char == 0xFFFD) { $outstr .= "\xFF\xFD"; // replacement character } elseif ($char < 0x10000) { $outstr .= chr($char >> 0x08); $outstr .= chr($char & 0xFF); } else { $char -= 0x10000; $w1 = 0xD800 | ($char >> 0x10); $w2 = 0xDC00 | ($char & 0x3FF); $outstr .= chr($w1 >> 0x08); $outstr .= chr($w1 & 0xFF); $outstr .= chr($w2 >> 0x08); $outstr .= chr($w2 & 0xFF); } } return $outstr; } // ==================================================== /** * Set header font. * @param array $font font * @since 1.1 */ function setHeaderFont($font) { $this->header_font = $font; } /** * Set footer font. * @param array $font font * @since 1.1 */ function setFooterFont($font) { $this->footer_font = $font; } /** * Set language array. * @param array $language * @since 1.1 */ function setLanguageArray($language) { $this->l = $language; } /** * Set document barcode. * @param string $bc barcode */ function setBarcode($bc="") { $this->barcode = $bc; } /** * Print Barcode. * @param int $x x position in user units * @param int $y y position in user units * @param int $w width in user units * @param int $h height position in user units * @param string $type type of barcode (I25, C128A, C128B, C128C, C39) * @param string $style barcode style * @param string $font font for text * @param int $xres x resolution * @param string $code code to print */ function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) { require_once(dirname(__FILE__)."/barcode/barcode.php"); require_once(dirname(__FILE__)."/barcode/i25object.php"); require_once(dirname(__FILE__)."/barcode/c39object.php"); require_once(dirname(__FILE__)."/barcode/c128aobject.php"); require_once(dirname(__FILE__)."/barcode/c128bobject.php"); require_once(dirname(__FILE__)."/barcode/c128cobject.php"); if (empty($code)) { return; } if (empty($style)) { $style = BCS_ALIGN_LEFT; $style |= BCS_IMAGE_PNG; $style |= BCS_TRANSPARENT; //$style |= BCS_BORDER; //$style |= BCS_DRAW_TEXT; //$style |= BCS_STRETCH_TEXT; //$style |= BCS_REVERSE_COLOR; } if (empty($font)) {$font = BCD_DEFAULT_FONT;} if (empty($xres)) {$xres = BCD_DEFAULT_XRES;} $scale_factor = 1.5 * $xres * $this->k; $bc_w = round($w * $scale_factor); //width in points $bc_h = round($h * $scale_factor); //height in points switch (strtoupper($type)) { case "I25": { $obj = new I25Object($bc_w, $bc_h, $style, $code); break; } case "C128A": { $obj = new C128AObject($bc_w, $bc_h, $style, $code); break; } default: case "C128B": { $obj = new C128BObject($bc_w, $bc_h, $style, $code); break; } case "C128C": { $obj = new C128CObject($bc_w, $bc_h, $style, $code); break; } case "C39": { $obj = new C39Object($bc_w, $bc_h, $style, $code); break; } } $obj->SetFont($font); $obj->DrawObject($xres); //use a temporary file.... $tmpName = tempnam(K_PATH_CACHE,'img'); imagepng($obj->getImage(), $tmpName); $this->Image($tmpName, $x, $y, $w, $h, 'png'); $obj->DestroyObject(); unset($obj); unlink($tmpName); } /** * Returns the PDF data. */ function getPDFData() { if($this->state < 3) { $this->Close(); } return $this->buffer; } // --- HTML PARSER FUNCTIONS --- /** * Allows to preserve some HTML formatting.
"); //remove all unsupported tags
//replace carriage returns, newlines and tabs
$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
$html = strtr($html, $repTable);
$pattern = '/(<[^>]+>)/Uu';
$a = preg_split($pattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //explodes the string
if (empty($this->lasth)) {
//set row height
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
}
foreach($a as $key=>$element) {
if (!preg_match($pattern, $element)) {
//Text
if($this->HREF) {
$this->addHtmlLink($this->HREF, $element, $fill);
}
elseif($this->tdbegin) {
if((strlen(trim($element)) > 0) AND ($element != " ")) {
$this->Cell($this->tdwidth, $this->tdheight, $this->unhtmlentities($element), $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
}
elseif($element == " ") {
$this->Cell($this->tdwidth, $this->tdheight, '', $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
}
}
else {
$this->Write($this->lasth, stripslashes($this->unhtmlentities($element)), '', $fill);
}
}
else {
$element = substr($element, 1, -1);
//Tag
if($element{0}=='/') {
$this->closedHTMLTagHandler(strtolower(substr($element, 1)));
}
else {
//Extract attributes
// get tag name
preg_match('/([a-zA-Z0-9]*)/', $element, $tag);
$tag = strtolower($tag[0]);
// get attributes
preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/', $element, $attr_array, PREG_PATTERN_ORDER);
$attr = array(); // reset attribute array
while(list($id,$name)=each($attr_array[1])) {
$attr[strtolower($name)] = $attr_array[2][$id];
}
$this->openHTMLTagHandler($tag, $attr, $fill);
}
}
}
if ($ln) {
$this->Ln($this->lasth);
}
}
/**
* Prints a cell (rectangular area) with optional borders, background color and html text string. The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.
* If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
* @param float $w Cell width. If 0, the cell extends up to the right margin.
* @param float $h Cell minimum height. The cell extends automatically if needed.
* @param float $x upper-left corner X coordinate
* @param float $y upper-left corner Y coordinate
* @param string $html html text to print. Default value: empty string.
* @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:
or a string containing some or all of the following characters (in any order):
* @param int $ln Indicates where the current position should go after the call. Possible values are:
Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @see Cell()
*/
function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0) {
if (empty($this->lasth)) {
//set row height
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
}
if (empty($x)) {
$x = $this->GetX();
}
if (empty($y)) {
$y = $this->GetY();
}
// get current page number
$pagenum = $this->page;
$this->SetX($x);
$this->SetY($y);
if(empty($w)) {
$w = $this->fw - $x - $this->rMargin;
}
// store original margin values
$lMargin = $this->lMargin;
$rMargin = $this->rMargin;
// set new margin values
$this->SetLeftMargin($x);
$this->SetRightMargin($this->fw - $x - $w);
// calculate remaining vertical space on page
$restspace = $this->getPageHeight() - $this->GetY() - $this->getBreakMargin();
$this->writeHTML($html, true, $fill); // write html text
$currentY = $this->GetY();
// check if a new page has been created
if ($this->page > $pagenum) {
// design a cell around the text on first page
$currentpage = $this->page;
$this->page = $pagenum;
$this->SetY($this->getPageHeight() - $restspace - $this->getBreakMargin());
$h = $restspace - 1;
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
// design a cell around the text on last page
$this->page = $currentpage;
$h = $currentY - $this->tMargin;
$this->SetY($this->tMargin); // put cursor at the beginning of text
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
} else {
$h = max($h, ($currentY - $y));
$this->SetY($y); // put cursor at the beginning of text
// design a cell around the text
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
}
// restore original margin values
$this->SetLeftMargin($lMargin);
$this->SetRightMargin($rMargin);
if ($ln) {
$this->Ln(0);
}
}
/**
* Process opening tags.
* @param string $tag tag name (in uppercase)
* @param string $attr tag attribute (in uppercase)
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @access private
*/
function openHTMLTagHandler($tag, $attr, $fill=0) {
//Opening tag
switch($tag) {
case 'table': {
if ((isset($attr['border'])) AND ($attr['border'] != '')) {
$this->tableborder = $attr['border'];
}
else {
$this->tableborder = 0;
}
break;
}
case 'tr': {
break;
}
case 'td':
case 'th': {
if ((isset($attr['width'])) AND ($attr['width'] != '')) {
$this->tdwidth = ($attr['width']/4);
}
else {
$this->tdwidth = (($this->w - $this->lMargin - $this->rMargin) / $this->default_table_columns);
}
if ((isset($attr['height'])) AND ($attr['height'] != '')) {
$this->tdheight=($attr['height'] / $this->k);
}
else {
$this->tdheight = $this->lasth;
}
if ((isset($attr['align'])) AND ($attr['align'] != '')) {
switch ($attr['align']) {
case 'center': {
$this->tdalign = "C";
break;
}
case 'right': {
$this->tdalign = "R";
break;
}
default:
case 'left': {
$this->tdalign = "L";
break;
}
}
}
if ((isset($attr['bgcolor'])) AND ($attr['bgcolor'] != '')) {
$coul = $this->convertColorHexToDec($attr['bgcolor']);
$this->SetFillColor($coul['R'], $coul['G'], $coul['B']);
$this->tdbgcolor=true;
}
$this->tdbegin=true;
break;
}
case 'hr': {
$this->Ln();
if ((isset($attr['width'])) AND ($attr['width'] != '')) {
$hrWidth = $attr['width'];
}
else {
$hrWidth = $this->w - $this->lMargin - $this->rMargin;
}
$x = $this->GetX();
$y = $this->GetY();
$this->SetLineWidth(0.2);
$this->Line($x, $y, $x + $hrWidth, $y);
$this->SetLineWidth(0.2);
$this->Ln();
break;
}
case 'strong': {
$this->setStyle('b', true);
break;
}
case 'em': {
$this->setStyle('i', true);
break;
}
case 'b':
case 'i':
case 'u': {
$this->setStyle($tag, true);
break;
}
case 'a': {
$this->HREF = $attr['href'];
break;
}
case 'img': {
if(isset($attr['src'])) {
// replace relative path with real server path
$attr['src'] = str_replace(K_PATH_URL_CACHE, K_PATH_CACHE, $attr['src']);
if(!isset($attr['width'])) {
$attr['width'] = 0;
}
if(!isset($attr['height'])) {
$attr['height'] = 0;
}
$this->Image($attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters($attr['width']), $this->pixelsToMillimeters($attr['height']));
//$this->SetX($this->img_rb_x);
$this->SetY($this->img_rb_y);
}
break;
}
case 'ul': {
$this->listordered = false;
$this->listcount = 0;
break;
}
case 'ol': {
$this->listordered = true;
$this->listcount = 0;
break;
}
case 'li': {
$this->Ln();
if ($this->listordered) {
$this->lispacer = " ".(++$this->listcount).". ";
}
else {
//unordered list simbol
$this->lispacer = " - ";
}
$this->Write($this->lasth, $this->lispacer, '', $fill);
break;
}
case 'blockquote':
case 'br': {
$this->Ln();
if(strlen($this->lispacer) > 0) {
$this->x += $this->GetStringWidth($this->lispacer);
}
break;
}
case 'p': {
$this->Ln();
$this->Ln();
break;
}
case 'sup': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'sub': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'small': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)/3));
break;
}
case 'font': {
if (isset($attr['color']) AND $attr['color']!='') {
$coul = $this->convertColorHexToDec($attr['color']);
$this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
$this->issetcolor=true;
}
if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist)) {
$this->SetFont(strtolower($attr['FACE']));
$this->issetfont=true;
}
if (isset($attr['size'])) {
$headsize = intval($attr['size']);
} else {
$headsize = 0;
}
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt + $headsize);
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6': {
$headsize = (4 - substr($tag, 1)) * 2;
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt + $headsize);
$this->setStyle('b', true);
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
}
}
/**
* Process closing tags.
* @param string $tag tag name (in uppercase)
* @access private
*/
function closedHTMLTagHandler($tag) {
//Closing tag
switch($tag) {
case 'td':
case 'th': {
$this->tdbegin = false;
$this->tdwidth = 0;
$this->tdheight = 0;
$this->tdalign = "L";
$this->tdbgcolor = false;
$this->SetFillColor($this->prevFillColor[0], $this->prevFillColor[1], $this->prevFillColor[2]);
break;
}
case 'tr': {
$this->Ln();
break;
}
case 'table': {
$this->tableborder=0;
break;
}
case 'strong': {
$this->setStyle('b', false);
break;
}
case 'em': {
$this->setStyle('i', false);
break;
}
case 'b':
case 'i':
case 'u': {
$this->setStyle($tag, false);
break;
}
case 'a': {
$this->HREF = '';
break;
}
case 'sup': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'sub': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'small': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() - (($this->FontSize - $currentFontSize)/3));
break;
}
case 'font': {
if ($this->issetcolor == true) {
$this->SetTextColor($this->prevTextColor[0], $this->prevTextColor[1], $this->prevTextColor[2]);
}
if ($this->issetfont) {
$this->FontFamily = $this->prevFontFamily;
$this->FontStyle = $this->prevFontStyle;
$this->SetFont($this->FontFamily);
$this->issetfont = false;
}
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
//$this->TextColor = $this->prevTextColor;
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
case 'ul': {
$this->Ln();
break;
}
case 'ol': {
$this->Ln();
break;
}
case 'li': {
$this->lispacer = "";
break;
}
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->setStyle('b', false);
$this->Ln();
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
default : {
break;
}
}
}
/**
* Sets font style.
* @param string $tag tag name (in lowercase)
* @param boolean $enable
* @access private
*/
function setStyle($tag, $enable) {
//Modify style and select corresponding font
$this->$tag += ($enable ? 1 : -1);
$style='';
foreach(array('b', 'i', 'u') as $s) {
if($this->$s > 0) {
$style .= $s;
}
}
$this->SetFont('', $style);
}
/**
* Output anchor link.
* @param string $url link URL
* @param string $name link name
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @access public
*/
function addHtmlLink($url, $name, $fill=0) {
//Put a hyperlink
$this->SetTextColor(0, 0, 255);
$this->setStyle('u', true);
$this->Write($this->lasth, $name, $url, $fill);
$this->setStyle('u', false);
$this->SetTextColor(0);
}
/**
* Returns an associative array (keys: R,G,B) from
* a hex html code (e.g. #3FE5AA).
* @param string $color hexadecimal html color [#rrggbb]
* @return array
* @access private
*/
function convertColorHexToDec($color = "#000000"){
$tbl_color = array();
$tbl_color['R'] = hexdec(substr($color, 1, 2));
$tbl_color['G'] = hexdec(substr($color, 3, 2));
$tbl_color['B'] = hexdec(substr($color, 5, 2));
return $tbl_color;
}
/**
* Converts pixels to millimeters in 72 dpi.
* @param int $px pixels
* @return float millimeters
* @access private
*/
function pixelsToMillimeters($px){
return $px * 25.4 / 72;
}
/**
* Reverse function for htmlentities.
* Convert entities in UTF-8.
*
* @param $text_to_convert Text to convert.
* @return string converted
*/
function unhtmlentities($text_to_convert) {
require_once(dirname(__FILE__).'/html_entity_decode_php4.php');
return html_entity_decode_php4($text_to_convert);
}
} // END OF CLASS
//Handle special IE contype request
if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
header('Content-Type: application/pdf');
exit;
}
}
//============================================================+
// END OF FILE
//============================================================+
?>