%PDF- %PDF-
Direktori : /home/tjamichg/intranet.tjamich.gob.mx/intranet/sistemas/control_folios/ |
Current File : /home/tjamichg/intranet.tjamich.gob.mx/intranet/sistemas/control_folios/flowing_blockv3.php |
<?php // FUNCIÓN SIN REQUIRE, CONVERTIR A STRING NÚMERO function convertirdia($numero) { $valor = array ('primero','segundo','tercero','cuarto', 'quinto','sexto','séptimo','octavo','noveno', 'décimo','undécimo','duodécimo','decimotercero', 'decimocuarto','decimoquinto ','decimosexto', 'decimoséptimo ','decimoctavo','decimonoveno', 'vigésimo', 'vigésimo primero','vigésimo segundo','vigésimo tercero','vigésimo cuarto', 'vigésimo quinto','vigésimo sexto','vigésimo séptimo','vigésimo octavo','vigésimo noveno', 'trigésimo', 'trigésimo primero'); return $valor[$numero - 1]; } // FUNCIONES PARA BLOQUES FLOTANTES // FUNCIONES PARA BLOQUES FLOTANTES // FUNCIONES PARA BLOQUES FLOTANTES // FUNCIONES PARA BLOQUES FLOTANTES // FUNCIONES PARA BLOQUES FLOTANTES // FUNCIONES PARA BLOQUES FLOTANTES require 'fpdf/fpdf.php'; class PDF_FlowingBlock extends FPDF { //FUNCIONES DE CELDA FLOTANTE //FUNCIONES DE CELDA FLOTANTE //FUNCIONES DE CELDA FLOTANTE //FUNCIONES DE CELDA FLOTANTE //FUNCIONES DE CELDA FLOTANTE // NOTA: SOLO PUEDEN ESTAR COLOCADAS A LA IZQUIERDA var $flowingBlockAttr; function saveFont() { $saved = array(); $saved[ 'family' ] = $this->FontFamily; $saved[ 'style' ] = $this->FontStyle; $saved[ 'sizePt' ] = $this->FontSizePt; $saved[ 'size' ] = $this->FontSize; $saved[ 'curr' ] =& $this->CurrentFont; return $saved; } function restoreFont( $saved ) { $this->FontFamily = $saved[ 'family' ]; $this->FontStyle = $saved[ 'style' ]; $this->FontSizePt = $saved[ 'sizePt' ]; $this->FontSize = $saved[ 'size' ]; $this->CurrentFont =& $saved[ 'curr' ]; if( $this->page > 0) $this->_out( sprintf( 'BT /F%d %.2F Tf ET', $this->CurrentFont[ 'i' ], $this->FontSizePt ) ); } function newFlowingBlock( $w, $h, $b = 0, $a = 'J', $f = 0 ) { // cell width in points $this->flowingBlockAttr[ 'width' ] = $w * $this->k; // line height in user units $this->flowingBlockAttr[ 'height' ] = $h; $this->flowingBlockAttr[ 'lineCount' ] = 0; $this->flowingBlockAttr[ 'border' ] = $b; $this->flowingBlockAttr[ 'align' ] = $a; $this->flowingBlockAttr[ 'fill' ] = $f; $this->flowingBlockAttr[ 'font' ] = array(); $this->flowingBlockAttr[ 'content' ] = array(); $this->flowingBlockAttr[ 'contentWidth' ] = 0; } function finishFlowingBlock() { $maxWidth =& $this->flowingBlockAttr[ 'width' ]; $lineHeight =& $this->flowingBlockAttr[ 'height' ]; $border =& $this->flowingBlockAttr[ 'border' ]; $align =& $this->flowingBlockAttr[ 'align' ]; $fill =& $this->flowingBlockAttr[ 'fill' ]; $content =& $this->flowingBlockAttr[ 'content' ]; $font =& $this->flowingBlockAttr[ 'font' ]; // set normal spacing $this->_out( sprintf( '%.3F Tw', 0 ) ); // print out each chunk // the amount of space taken up so far in user units $usedWidth = 0; foreach ( $content as $k => $chunk ) { $b = ''; if ( is_int( strpos( $border, 'B' ) ) ) $b .= 'B'; if ( $k == 0 && is_int( strpos( $border, 'L' ) ) ) $b .= 'L'; if ( $k == count( $content ) - 1 && is_int( strpos( $border, 'R' ) ) ) $b .= 'R'; $this->restoreFont( $font[ $k ] ); // if it's the last chunk of this line, move to the next line after if ( $k == count( $content ) - 1 ) $this->Cell( ( $maxWidth / $this->k ) - $usedWidth + 2 * $this->cMargin, $lineHeight, $chunk, $b, 1, $align, $fill ); else $this->Cell( $this->GetStringWidth( $chunk ), $lineHeight, $chunk, $b, 0, $align, $fill ); $usedWidth += $this->GetStringWidth( $chunk ); } } function WriteFlowingBlock( $s ) { // width of all the content so far in points $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ]; // cell width in points $maxWidth =& $this->flowingBlockAttr[ 'width' ]; $lineCount =& $this->flowingBlockAttr[ 'lineCount' ]; // line height in user units $lineHeight =& $this->flowingBlockAttr[ 'height' ]; $border =& $this->flowingBlockAttr[ 'border' ]; $align =& $this->flowingBlockAttr[ 'align' ]; $fill =& $this->flowingBlockAttr[ 'fill' ]; $content =& $this->flowingBlockAttr[ 'content' ]; $font =& $this->flowingBlockAttr[ 'font' ]; $font[] = $this->saveFont(); $content[] = ''; $currContent =& $content[ count( $content ) - 1 ]; // where the line should be cutoff if it is to be justified $cutoffWidth = $contentWidth; // for every character in the string for ( $i = 0; $i < strlen( $s ); $i++ ) { // extract the current character $c = $s[ $i ]; // get the width of the character in points $cw = $this->CurrentFont[ 'cw' ][ $c ] * ( $this->FontSizePt / 1000 ); if ( $c == ' ' ) { $currContent .= ' '; $cutoffWidth = $contentWidth; $contentWidth += $cw; continue; } // try adding another char if ( $contentWidth + $cw > $maxWidth ) { // won't fit, output what we have $lineCount++; // contains any content that didn't make it into this print $savedContent = ''; $savedFont = array(); // first, cut off and save any partial words at the end of the string $words = explode( ' ', $currContent ); // if it looks like we didn't finish any words for this chunk if ( count( $words ) == 1 ) { // save and crop off the content currently on the stack $savedContent = array_pop( $content ); $savedFont = array_pop( $font ); // trim any trailing spaces off the last bit of content $currContent =& $content[ count( $content ) - 1 ]; $currContent = rtrim( $currContent ); } // otherwise, we need to find which bit to cut off else { $lastContent = ''; for ( $w = 0; $w < count( $words ) - 1; $w++) $lastContent .= "{$words[ $w ]} "; $savedContent = $words[ count( $words ) - 1 ]; $savedFont = $this->saveFont(); // replace the current content with the cropped version $currContent = rtrim( $lastContent ); } // update $contentWidth and $cutoffWidth since they changed with cropping $contentWidth = 0; foreach ( $content as $k => $chunk ) { $this->restoreFont( $font[ $k ] ); $contentWidth += $this->GetStringWidth( $chunk ) * $this->k; } $cutoffWidth = $contentWidth; // if it's justified, we need to find the char spacing if( $align == 'J' ) { // count how many spaces there are in the entire content string $numSpaces = 0; foreach ( $content as $chunk ) $numSpaces += substr_count( $chunk, ' ' ); // if there's more than one space, find word spacing in points if ( $numSpaces > 0 ) $this->ws = ( $maxWidth - $cutoffWidth ) / $numSpaces; else $this->ws = 0; $this->_out( sprintf( '%.3F Tw', $this->ws ) ); } // otherwise, we want normal spacing else $this->_out( sprintf( '%.3F Tw', 0 ) ); // print out each chunk $usedWidth = 0; foreach ( $content as $k => $chunk ) { $this->restoreFont( $font[ $k ] ); $stringWidth = $this->GetStringWidth( $chunk ) + ( $this->ws * substr_count( $chunk, ' ' ) / $this->k ); // determine which borders should be used $b = ''; if ( $lineCount == 1 && is_int( strpos( $border, 'T' ) ) ) $b .= 'T'; if ( $k == 0 && is_int( strpos( $border, 'L' ) ) ) $b .= 'L'; if ( $k == count( $content ) - 1 && is_int( strpos( $border, 'R' ) ) ) $b .= 'R'; // if it's the last chunk of this line, move to the next line after if ( $k == count( $content ) - 1 ) $this->Cell( ( $maxWidth / $this->k ) - $usedWidth + 2 * $this->cMargin, $lineHeight, $chunk, $b, 1, $align, $fill ); else { $this->Cell( $stringWidth + 2 * $this->cMargin, $lineHeight, $chunk, $b, 0, $align, $fill ); $this->x -= 2 * $this->cMargin; } $usedWidth += $stringWidth; } // move on to the next line, reset variables, tack on saved content and current char $this->restoreFont( $savedFont ); $font = array( $savedFont ); $content = array( $savedContent . $s[ $i ] ); $currContent =& $content[ 0 ]; $contentWidth = $this->GetStringWidth( $currContent ) * $this->k; $cutoffWidth = $contentWidth; } // another character will fit, so add it on else { $contentWidth += $cw; $currContent .= $s[ $i ]; } } } //FUNCIONES DE WRITE-HTML //FUNCIONES DE WRITE-HTML //FUNCIONES DE WRITE-HTML //FUNCIONES DE WRITE-HTML //FUNCIONES DE WRITE-HTML var $B=0; var $I=0; var $U=0; var $HREF=''; var $ALIGN=''; // Esta WirteHTML hasta justo antes de Justify permite cargar texto en html para cargar estilos de texto y otras funciones function WriteHTML($html) { //HTML parser $html=str_replace("\n",' ',$html); $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE); foreach($a as $i=>$e) { if($i%2==0) { //Text if($this->HREF) $this->PutLink($this->HREF,$e); elseif($this->ALIGN=='center') $this->Cell(0,5,$e,0,1,'C'); else $this->Write(5,$e); } else { //Tag if($e[0]=='/') $this->CloseTag(strtoupper(substr($e,1))); else { //Extract properties $a2=explode(' ',$e); $tag=strtoupper(array_shift($a2)); $prop=array(); foreach($a2 as $v) { if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3)) $prop[strtoupper($a3[1])]=$a3[2]; } $this->OpenTag($tag,$prop); } } } } function OpenTag($tag,$prop) { //Opening tag if($tag=='B' || $tag=='I' || $tag=='U') $this->SetStyle($tag,true); if($tag=='A') $this->HREF=$prop['HREF']; if($tag=='BR') $this->Ln(5); if($tag=='P') $this->ALIGN=$prop['ALIGN']; if($tag=='HR') { if( !empty($prop['WIDTH']) ) $Width = $prop['WIDTH']; else $Width = $this->w - $this->lMargin-$this->rMargin; $this->Ln(2); $x = $this->GetX(); $y = $this->GetY(); $this->SetLineWidth(0.4); $this->Line($x,$y,$x+$Width,$y); $this->SetLineWidth(0.2); $this->Ln(2); } } function CloseTag($tag) { //Closing tag if($tag=='B' || $tag=='I' || $tag=='U') $this->SetStyle($tag,false); if($tag=='A') $this->HREF=''; if($tag=='P') $this->ALIGN=''; } 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); } function PutLink($URL,$txt) { //Put a hyperlink $this->SetTextColor(0,0,255); $this->SetStyle('U',true); $this->Write(5,$txt,$URL); $this->SetStyle('U',false); $this->SetTextColor(0); } //FUNCION JUSTIFY SOLO SIN FORMATO HMTL NI ESTILOS //FUNCION JUSTIFY SOLO SIN FORMATO HMTL NI ESTILOS //FUNCION JUSTIFY SOLO SIN FORMATO HMTL NI ESTILOS //FUNCION JUSTIFY SOLO SIN FORMATO HMTL NI ESTILOS //FUNCION JUSTIFY SOLO SIN FORMATO HMTL NI ESTILOS function Justify($text, $w, $h) { $tab_paragraphe = explode("\n", $text); $nb_paragraphe = count($tab_paragraphe); $j = 0; while ($j<$nb_paragraphe) { $paragraphe = $tab_paragraphe[$j]; $tab_mot = explode(' ', $paragraphe); $nb_mot = count($tab_mot); // Handle strings longer than paragraph width $k=0; $l=0; while ($k<$nb_mot) { $len_mot = strlen ($tab_mot[$k]); if ($len_mot<($w-5) ) { $tab_mot2[$l] = $tab_mot[$k]; $l++; } else { $m=0; $chaine_lettre=''; while ($m<$len_mot) { $lettre = substr($tab_mot[$k], $m, 1); $len_chaine_lettre = $this->GetStringWidth($chaine_lettre.$lettre); if ($len_chaine_lettre>($w-7)) { $tab_mot2[$l] = $chaine_lettre . '-'; $chaine_lettre = $lettre; $l++; } else { $chaine_lettre .= $lettre; } $m++; } if ($chaine_lettre) { $tab_mot2[$l] = $chaine_lettre; $l++; } } $k++; } // Justified lines $nb_mot = count($tab_mot2); $i=0; $ligne = ''; while ($i<$nb_mot) { $mot = $tab_mot2[$i]; $len_ligne = $this->GetStringWidth($ligne . ' ' . $mot); if ($len_ligne>($w-5)) { $len_ligne = $this->GetStringWidth($ligne); $nb_carac = strlen ($ligne); $ecart = (($w-2) - $len_ligne) / $nb_carac; $this->_out(sprintf('BT %.3F Tc ET',$ecart*$this->k)); $this->MultiCell($w,$h,$ligne); $ligne = $mot; } else { if ($ligne) { $ligne .= ' ' . $mot; } else { $ligne = $mot; } } $i++; } // Last line $this->_out('BT 0 Tc ET'); $this->MultiCell($w,$h,$ligne); $tab_mot = ''; $tab_mot2 = ''; $j++; } } //FUNCION CELL FORZAR JUSTIFICACIÓN //FUNCION CELL FORZAR JUSTIFICACIÓN //FUNCION CELL FORZAR JUSTIFICACIÓN //FUNCION CELL FORZAR JUSTIFICACIÓN //FUNCION CELL FORZAR JUSTIFICACIÓN function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') { $k=$this->k; if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) { $x=$this->x; $ws=$this->ws; if($ws>0) { $this->ws=0; $this->_out('0 Tw'); } $this->AddPage($this->CurOrientation); $this->x=$x; if($ws>0) { $this->ws=$ws; $this->_out(sprintf('%.3F Tw', $ws*$k)); } } if($w==0) $w=$this->w-$this->rMargin-$this->x; $s=''; if($fill || $border==1) { if($fill) $op=($border==1) ? 'B' : 'f'; else $op='S'; $s=sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x*$k, ($this->h-$this->y)*$k, $w*$k, -$h*$k, $op); } if(is_string($border)) { $x=$this->x; $y=$this->y; if(is_int(strpos($border, 'L'))) $s.=sprintf('%.2F %.2F m %.2F %.2F l S ', $x*$k, ($this->h-$y)*$k, $x*$k, ($this->h-($y+$h))*$k); if(is_int(strpos($border, 'T'))) $s.=sprintf('%.2F %.2F m %.2F %.2F l S ', $x*$k, ($this->h-$y)*$k, ($x+$w)*$k, ($this->h-$y)*$k); if(is_int(strpos($border, 'R'))) $s.=sprintf('%.2F %.2F m %.2F %.2F l S ', ($x+$w)*$k, ($this->h-$y)*$k, ($x+$w)*$k, ($this->h-($y+$h))*$k); if(is_int(strpos($border, 'B'))) $s.=sprintf('%.2F %.2F m %.2F %.2F l S ', $x*$k, ($this->h-($y+$h))*$k, ($x+$w)*$k, ($this->h-($y+$h))*$k); } if($txt!='') { if($align=='R') $dx=$w-$this->cMargin-$this->GetStringWidth($txt); elseif($align=='C') $dx=($w-$this->GetStringWidth($txt))/2; elseif($align=='FJ') { //Set word spacing $wmax=($w-2*$this->cMargin); $this->ws=($wmax-$this->GetStringWidth($txt))/substr_count($txt, ' '); $this->_out(sprintf('%.3F Tw', $this->ws*$this->k)); $dx=$this->cMargin; } else $dx=$this->cMargin; $txt=str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); if($this->ColorFlag) $s.='q '.$this->TextColor.' '; $s.=sprintf('BT %.2F %.2F Td (%s) Tj ET', ($this->x+$dx)*$k, ($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k, $txt); if($this->underline) $s.=' '.$this->_dounderline($this->x+$dx, $this->y+.5*$h+.3*$this->FontSize, $txt); if($this->ColorFlag) $s.=' Q'; if($link) { if($align=='FJ') $wlink=$wmax; else $wlink=$this->GetStringWidth($txt); $this->Link($this->x+$dx, $this->y+.5*$h-.5*$this->FontSize, $wlink, $this->FontSize, $link); } } if($s) $this->_out($s); if($align=='FJ') { //Remove word spacing $this->_out('0 Tw'); $this->ws=0; } $this->lasth=$h; if($ln>0) { $this->y+=$h; if($ln==1) $this->x=$this->lMargin; } else $this->x+=$w; } //FUNCION NUMERO Y FECHA A TEXTO //FUNCION NUMERO Y FECHA A TEXTO //FUNCION NUMERO Y FECHA A TEXTO //FUNCION NUMERO Y FECHA A TEXTO //FUNCION NUMERO Y FECHA A TEXTO //------ CONVERTIR NUMEROS A LETRAS --------------- //------ Máxima cifra soportada: 18 dígitos con 2 decimales //------ 999,999,999,999,999,999.99 // NOVECIENTOS NOVENTA Y NUEVE MIL NOVECIENTOS NOVENTA Y NUEVE BILLONES // NOVECIENTOS NOVENTA Y NUEVE MIL NOVECIENTOS NOVENTA Y NUEVE MILLONES // NOVECIENTOS NOVENTA Y NUEVE MIL NOVECIENTOS NOVENTA Y NUEVE PESOS 99/100 M.N. //------ Creada por: --------------- //------ ULTIMINIO RAMOS GALÁN --------------- //------ uramos@gmail.com --------------- //------ 10 de junio de 2009. México, D.F. --------------- //------ PHP Version 4.3.1 o mayores (aunque podría funcionar en versiones anteriores, tendrías que probar) function numtoletras($xcifra) { $xarray = array(0 => "Cero", 1 => "UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE", "DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECISEIS", "DIECISIETE", "DIECIOCHO", "DIECINUEVE", "VEINTI", 30 => "TREINTA", 40 => "CUARENTA", 50 => "CINCUENTA", 60 => "SESENTA", 70 => "SETENTA", 80 => "OCHENTA", 90 => "NOVENTA", 100 => "CIENTO", 200 => "DOSCIENTOS", 300 => "TRESCIENTOS", 400 => "CUATROCIENTOS", 500 => "QUINIENTOS", 600 => "SEISCIENTOS", 700 => "SETECIENTOS", 800 => "OCHOCIENTOS", 900 => "NOVECIENTOS" ); // $xcifra = trim($xcifra); $xlength = strlen($xcifra); $xpos_punto = strpos($xcifra, "."); $xaux_int = $xcifra; $xdecimales = "00"; if (!($xpos_punto === false)) { if ($xpos_punto == 0) { $xcifra = "0" . $xcifra; $xpos_punto = strpos($xcifra, "."); } $xaux_int = substr($xcifra, 0, $xpos_punto); // obtengo el entero de la cifra a covertir $xdecimales = substr($xcifra . "00", $xpos_punto + 1, 2); // obtengo los valores decimales } $XAUX = str_pad($xaux_int, 18, " ", STR_PAD_LEFT); // ajusto la longitud de la cifra, para que sea divisible por centenas de miles (grupos de 6) $xcadena = ""; for ($xz = 0; $xz < 3; $xz++) { $xaux = substr($XAUX, $xz * 6, 6); $xi = 0; $xlimite = 6; // inicializo el contador de centenas xi y establezco el límite a 6 dígitos en la parte entera $xexit = true; // bandera para controlar el ciclo del While while ($xexit) { if ($xi == $xlimite) { // si ya llegó al límite máximo de enteros break; // termina el ciclo } $x3digitos = ($xlimite - $xi) * -1; // comienzo con los tres primeros digitos de la cifra, comenzando por la izquierda $xaux = substr($xaux, $x3digitos, abs($x3digitos)); // obtengo la centena (los tres dígitos) for ($xy = 1; $xy < 4; $xy++) { // ciclo para revisar centenas, decenas y unidades, en ese orden switch ($xy) { case 1: // checa las centenas if (substr($xaux, 0, 3) < 100) { // si el grupo de tres dígitos es menor a una centena ( < 99) no hace nada y pasa a revisar las decenas } else { $key = (int) substr($xaux, 0, 3); if (TRUE === array_key_exists($key, $xarray)){ // busco si la centena es número redondo (100, 200, 300, 400, etc..) $xseek = $xarray[$key]; $xsub = subfijo($xaux); // devuelve el subfijo correspondiente (Millón, Millones, Mil o nada) if (substr($xaux, 0, 3) == 100) $xcadena = " " . $xcadena . " CIEN " . $xsub; else $xcadena = " " . $xcadena . " " . $xseek . " " . $xsub; $xy = 3; // la centena fue redonda, entonces termino el ciclo del for y ya no reviso decenas ni unidades } else { // entra aquí si la centena no fue numero redondo (101, 253, 120, 980, etc.) $key = (int) substr($xaux, 0, 1) * 100; $xseek = $xarray[$key]; // toma el primer caracter de la centena y lo multiplica por cien y lo busca en el arreglo (para que busque 100,200,300, etc) $xcadena = " " . $xcadena . " " . $xseek; } // ENDIF ($xseek) } // ENDIF (substr($xaux, 0, 3) < 100) break; case 2: // checa las decenas (con la misma lógica que las centenas) if (substr($xaux, 1, 2) < 10) { } else { $key = (int) substr($xaux, 1, 2); if (TRUE === array_key_exists($key, $xarray)) { $xseek = $xarray[$key]; $xsub = subfijo($xaux); if (substr($xaux, 1, 2) == 20) $xcadena = " " . $xcadena . " VEINTE " . $xsub; else $xcadena = " " . $xcadena . " " . $xseek . " " . $xsub; $xy = 3; } else { $key = (int) substr($xaux, 1, 1) * 10; $xseek = $xarray[$key]; if (20 == substr($xaux, 1, 1) * 10) $xcadena = " " . $xcadena . " " . $xseek; else $xcadena = " " . $xcadena . " " . $xseek . " Y "; } // ENDIF ($xseek) } // ENDIF (substr($xaux, 1, 2) < 10) break; case 3: // checa las unidades if (substr($xaux, 2, 1) < 1) { // si la unidad es cero, ya no hace nada } else { $key = (int) substr($xaux, 2, 1); $xseek = $xarray[$key]; // obtengo directamente el valor de la unidad (del uno al nueve) $xsub = subfijo($xaux); $xcadena = " " . $xcadena . " " . $xseek . " " . $xsub; } // ENDIF (substr($xaux, 2, 1) < 1) break; } // END SWITCH } // END FOR $xi = $xi + 3; } // ENDDO if (substr(trim($xcadena), -5, 5) == "ILLON") // si la cadena obtenida termina en MILLON o BILLON, entonces le agrega al final la conjuncion DE $xcadena.= " DE"; if (substr(trim($xcadena), -7, 7) == "ILLONES") // si la cadena obtenida en MILLONES o BILLONES, entoncea le agrega al final la conjuncion DE $xcadena.= " DE"; // ----------- esta línea la puedes cambiar de acuerdo a tus necesidades o a tu país ------- if (trim($xaux) != "") { switch ($xz) { case 0: if (trim(substr($XAUX, $xz * 6, 6)) == "1") $xcadena.= "UN BILLON "; else $xcadena.= " BILLONES "; break; case 1: if (trim(substr($XAUX, $xz * 6, 6)) == "1") $xcadena.= "UN MILLON "; else $xcadena.= " MILLONES "; break; case 2: if ($xcifra < 1) { //$xcadena = "CERO PESOS $xdecimales/100 M.N."; } if ($xcifra >= 1 && $xcifra < 2) { //$xcadena = "UN PESO $xdecimales/100 M.N. "; } if ($xcifra >= 2) { //$xcadena.= " PESOS $xdecimales/100 M.N. "; // } break; } // endswitch ($xz) } // ENDIF (trim($xaux) != "") // ------------------ en este caso, para México se usa esta leyenda ---------------- $xcadena = str_replace("VEINTI ", "VEINTI", $xcadena); // quito el espacio para el VEINTI, para que quede: VEINTICUATRO, VEINTIUN, VEINTIDOS, etc $xcadena = str_replace(" ", " ", $xcadena); // quito espacios dobles $xcadena = str_replace("UN UN", "UN", $xcadena); // quito la duplicidad $xcadena = str_replace(" ", " ", $xcadena); // quito espacios dobles $xcadena = str_replace("BILLON DE MILLONES", "BILLON DE", $xcadena); // corrigo la leyenda $xcadena = str_replace("BILLONES DE MILLONES", "BILLONES DE", $xcadena); // corrigo la leyenda $xcadena = str_replace("DE UN", "UN", $xcadena); // corrigo la leyenda $xcadena = str_replace("DIECISEIS", "DIECISéIS", $xcadena); // corrigo la leyenda $xcadena = str_replace("VEINTIUN", "VEINTIúN", $xcadena); // corrigo la leyenda $xcadena = str_replace("VEINTISEIS", "VEINTISéIS", $xcadena); // corrigo la leyenda } // ENDFOR ($xz) return trim($xcadena); } // END FUNCTION function subfijo($xx) { // esta función regresa un subfijo para la cifra $xx = trim($xx); $xstrlen = strlen($xx); if ($xstrlen == 1 || $xstrlen == 2 || $xstrlen == 3) $xsub = ""; // if ($xstrlen == 4 || $xstrlen == 5 || $xstrlen == 6) $xsub = "MIL"; // return $xsub; } // END FUNCTION /*------------------------------------------------------------------ * hug0 * Blog Kiuvox * funcion para generar la fecha en letras * http://blog.kiuvox.com * ---------------------------------------------------------------- */ function fechaATexto($fecha){ $fecha_separada=explode("-", $fecha); $dia= strtolower(numtoletras($fecha_separada[0])); switch ($fecha_separada[1]) { case "01": $mes="ENERO"; break; case "02": $mes="FEBRERO"; break; case "03": $mes="MARZO"; break; case "04": $mes="ABRIL"; break; case "05": $mes="MAYO"; break; case "06": $mes="JUNIO"; break; case "07": $mes="JULIO"; break; case "08": $mes="AGOSTO"; break; case "09": $mes="SEPTIEMBRE"; break; case "10": $mes="OCTUBRE"; break; case "11": $mes="NOVIEMBRE"; break; case "12": $mes="DICIEMBRE"; break; default: break; } $anio= strtolower(numtoletras($fecha_separada[2])); return "$dia DE $mes DEL $anio."; } function mesATexto($fecha){ switch ($fecha) { case "01": $mes="ENERO"; break; case "02": $mes="FEBRERO"; break; case "03": $mes="MARZO"; break; case "04": $mes="ABRIL"; break; case "05": $mes="MAYO"; break; case "06": $mes="JUNIO"; break; case "07": $mes="JULIO"; break; case "08": $mes="AGOSTO"; break; case "09": $mes="SEPTIEMBRE"; break; case "10": $mes="OCTUBRE"; break; case "11": $mes="NOVIEMBRE"; break; case "12": $mes="DICIEMBRE"; break; default: break; } return "$mes"; } // FUNCION FOOTER - (AUTOMATIZADO) // FUNCION FOOTER - (AUTOMATIZADO) // FUNCION FOOTER - (AUTOMATIZADO) // FUNCION FOOTER - (AUTOMATIZADO) // FUNCION FOOTER - (AUTOMATIZADO) //USAR : $pdf->AliasNbPages(); ANTES DE : $pdf->AddPage(); function Footer() { // Position at 1.5 cm from bottom $this->SetY(-15); // Arial italic 8 $this->SetFont('Arial','I',8); // Page number $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C'); // $this->Cell(0,10,'Pagina '.$this->PageNo().'',0,0,'C'); } // CABECERA AUTOMATICA CON LOGO // CABECERA AUTOMATICA CON LOGO // CABECERA AUTOMATICA CON LOGO // CABECERA AUTOMATICA CON LOGO // CABECERA AUTOMATICA CON LOGO /*function Header() { // Logo $this->Image('logo.png',10,6,30); // Arial bold 15 $this->SetFont('Arial','B',15); // Move to the right $this->Cell(80); // Title $this->Cell(30,10,'Title',1,0,'C'); // Line break $this->Ln(20); }*/ //FUNCION TRANSPARENCIA DE TEXTO/IMAGEN ALPHA //FUNCION TRANSPARENCIA DE TEXTO/IMAGEN ALPHA //FUNCION TRANSPARENCIA DE TEXTO/IMAGEN ALPHA //FUNCION TRANSPARENCIA DE TEXTO/IMAGEN ALPHA //FUNCION TRANSPARENCIA DE TEXTO/IMAGEN ALPHA protected $extgstates = array(); // alpha: real value from 0 (transparent) to 1 (opaque) // bm: blend mode, one of the following: // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity function SetAlpha($alpha, $bm='Normal') { // set alpha for stroking (CA) and non-stroking (ca) operations $gs = $this->AddExtGState(array('ca'=>$alpha, 'CA'=>$alpha, 'BM'=>'/'.$bm)); $this->SetExtGState($gs); } function AddExtGState($parms) { $n = count($this->extgstates)+1; $this->extgstates[$n]['parms'] = $parms; return $n; } function SetExtGState($gs) { $this->_out(sprintf('/GS%d gs', $gs)); } function _enddoc() { if(!empty($this->extgstates) && $this->PDFVersion<'1.4') $this->PDFVersion='1.4'; parent::_enddoc(); } function _putextgstates() { for ($i = 1; $i <= count($this->extgstates); $i++) { $this->_newobj(); $this->extgstates[$i]['n'] = $this->n; $this->_put('<</Type /ExtGState'); $parms = $this->extgstates[$i]['parms']; $this->_put(sprintf('/ca %.3F', $parms['ca'])); $this->_put(sprintf('/CA %.3F', $parms['CA'])); $this->_put('/BM '.$parms['BM']); $this->_put('>>'); $this->_put('endobj'); } } function _putresourcedict() { parent::_putresourcedict(); $this->_put('/ExtGState <<'); foreach($this->extgstates as $k=>$extgstate) $this->_put('/GS'.$k.' '.$extgstate['n'].' 0 R'); $this->_put('>>'); } function _putresources() { $this->_putextgstates(); parent::_putresources(); } } // EXPANSIÓN PARA WRITE HTML // EXPANSIÓN PARA WRITE HTML // EXPANSIÓN PARA WRITE HTML // EXPANSIÓN PARA WRITE HTML // EXPANSIÓN PARA WRITE HTML // function hex2dec($couleur = "#000000"){ // $R = substr($couleur, 1, 2); // $rouge = hexdec($R); // $V = substr($couleur, 3, 2); // $vert = hexdec($V); // $B = substr($couleur, 5, 2); // $bleu = hexdec($B); // $tbl_couleur = array(); // $tbl_couleur['R']=$rouge; // $tbl_couleur['G']=$vert; // $tbl_couleur['B']=$bleu; // return $tbl_couleur; // } // //conversion pixel -> millimeter in 72 dpi // function px2mm($px){ // return $px*25.4/72; // } // function txtentities($html){ // $trans = get_html_translation_table(HTML_ENTITIES); // $trans = array_flip($trans); // return strtr($html, $trans); // } // //////////////////////////////////// // class PDF extends FPDF // { // //variables of html parser // protected $B; // protected $I; // protected $U; // protected $HREF; // protected $fontList; // protected $issetfont; // protected $issetcolor; // function __construct($orientation='P', $unit='mm', $format='A4') // { // //Call parent constructor // parent::__construct($orientation,$unit,$format); // //Initialization // $this->B=0; // $this->I=0; // $this->U=0; // $this->HREF=''; // $this->tableborder=0; // $this->tdbegin=false; // $this->tdwidth=0; // $this->tdheight=0; // $this->tdalign="L"; // $this->tdbgcolor=false; // $this->oldx=0; // $this->oldy=0; // $this->fontlist=array("arial","times","courier","helvetica","symbol"); // $this->issetfont=false; // $this->issetcolor=false; // } // ////////////////////////////////////// // //html parser // function WriteHTML($html) // { // $html=strip_tags($html,"<b><u><i><a><img><p><br><strong><em><font><tr><blockquote><hr><td><tr><table><sup>"); //remove all unsupported tags // $html=str_replace("\n",'',$html); //replace carriage returns with spaces // $html=str_replace("\t",'',$html); //replace carriage returns with spaces // $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE); //explode the string // foreach($a as $i=>$e) // { // if($i%2==0) // { // //Text // if($this->HREF) // $this->PutLink($this->HREF,$e); // elseif($this->tdbegin) { // if(trim($e)!='' && $e!=" ") { // $this->Cell($this->tdwidth,$this->tdheight,$e,$this->tableborder,'',$this->tdalign,$this->tdbgcolor); // } // elseif($e==" ") { // $this->Cell($this->tdwidth,$this->tdheight,'',$this->tableborder,'',$this->tdalign,$this->tdbgcolor); // } // } // else // $this->Write(5,stripslashes(txtentities($e))); // } // else // { // //Tag // if($e[0]=='/') // $this->CloseTag(strtoupper(substr($e,1))); // else // { // //Extract attributes // $a2=explode(' ',$e); // $tag=strtoupper(array_shift($a2)); // $attr=array(); // foreach($a2 as $v) // { // if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3)) // $attr[strtoupper($a3[1])]=$a3[2]; // } // $this->OpenTag($tag,$attr); // } // } // } // } // function OpenTag($tag, $attr) // { // //Opening tag // switch($tag){ // case 'SUP': // if( !empty($attr['SUP']) ) { // //Set current font to 6pt // $this->SetFont('','',6); // //Start 125cm plus width of cell to the right of left margin // //Superscript "1" // $this->Cell(2,2,$attr['SUP'],0,0,'L'); // } // break; // case 'TABLE': // TABLE-BEGIN // if( !empty($attr['BORDER']) ) $this->tableborder=$attr['BORDER']; // else $this->tableborder=0; // break; // case 'TR': //TR-BEGIN // break; // case 'TD': // TD-BEGIN // if( !empty($attr['WIDTH']) ) $this->tdwidth=($attr['WIDTH']/4); // else $this->tdwidth=40; // Set to your own width if you need bigger fixed cells // if( !empty($attr['HEIGHT']) ) $this->tdheight=($attr['HEIGHT']/6); // else $this->tdheight=6; // Set to your own height if you need bigger fixed cells // if( !empty($attr['ALIGN']) ) { // $align=$attr['ALIGN']; // if($align=='LEFT') $this->tdalign='L'; // if($align=='CENTER') $this->tdalign='C'; // if($align=='RIGHT') $this->tdalign='R'; // } // else $this->tdalign='L'; // Set to your own // if( !empty($attr['BGCOLOR']) ) { // $coul=hex2dec($attr['BGCOLOR']); // $this->SetFillColor($coul['R'],$coul['G'],$coul['B']); // $this->tdbgcolor=true; // } // $this->tdbegin=true; // break; // case 'HR': // if( !empty($attr['WIDTH']) ) // $Width = $attr['WIDTH']; // else // $Width = $this->w - $this->lMargin-$this->rMargin; // $x = $this->GetX(); // $y = $this->GetY(); // $this->SetLineWidth(0.2); // $this->Line($x,$y,$x+$Width,$y); // $this->SetLineWidth(0.2); // $this->Ln(1); // 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']) && (isset($attr['WIDTH']) || isset($attr['HEIGHT']))) { // if(!isset($attr['WIDTH'])) // $attr['WIDTH'] = 0; // if(!isset($attr['HEIGHT'])) // $attr['HEIGHT'] = 0; // $this->Image($attr['SRC'], $this->GetX(), $this->GetY(), px2mm($attr['WIDTH']), px2mm($attr['HEIGHT'])); // } // break; // case 'BLOCKQUOTE': // case 'BR': // $this->Ln(5); // break; // case 'P': // $this->Ln(10); // break; // case 'FONT': // if (isset($attr['COLOR']) && $attr['COLOR']!='') { // $coul=hex2dec($attr['COLOR']); // $this->SetTextColor($coul['R'],$coul['G'],$coul['B']); // $this->issetcolor=true; // } // if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist)) { // $this->SetFont(strtolower($attr['FACE'])); // $this->issetfont=true; // } // if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist) && isset($attr['SIZE']) && $attr['SIZE']!='') { // $this->SetFont(strtolower($attr['FACE']),'',$attr['SIZE']); // $this->issetfont=true; // } // break; // } // } // function CloseTag($tag) // { // //Closing tag // if($tag=='SUP') { // } // if($tag=='TD') { // TD-END // $this->tdbegin=false; // $this->tdwidth=0; // $this->tdheight=0; // $this->tdalign="L"; // $this->tdbgcolor=false; // } // if($tag=='TR') { // TR-END // $this->Ln(); // } // if($tag=='TABLE') { // TABLE-END // $this->tableborder=0; // } // if($tag=='STRONG') // $tag='B'; // if($tag=='EM') // $tag='I'; // if($tag=='B' || $tag=='I' || $tag=='U') // $this->SetStyle($tag,false); // if($tag=='A') // $this->HREF=''; // if($tag=='FONT'){ // if ($this->issetcolor==true) { // $this->SetTextColor(0); // } // if ($this->issetfont) { // $this->SetFont('arial'); // $this->issetfont=false; // } // } // } // 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); // } // function PutLink($URL, $txt) // { // //Put a hyperlink // $this->SetTextColor(0,0,255); // $this->SetStyle('U',true); // $this->Write(5,$txt,$URL); // $this->SetStyle('U',false); // $this->SetTextColor(0); // } // } ?>