sábado, 31 de marzo de 2012

PHP: leer excel desde php con libreria PHPExcelReader

<?php
set_time_limit(0);
require_once 'Excel/reader.php';
 
$data = new Spreadsheet_Excel_Reader();
 
// $data->setOutputEncoding('CP1251');
 
$data->read('alumno_notas.xls');
 
$filas = $data->sheets[0]['cells']; //[fila][columna].

// echo count($filas);
// echo "<br>";
// echo $filas[1][1];

for($z=1; $z<count($filas); $z++)
{
    echo $filas[$z][1]."<br>";
}
?>

jueves, 22 de marzo de 2012

jQuery: comprobar si el formulario esta vacio

function comprobarSiFormEstaVacio(aFormId) {

var campos = $("#"+aFormId).serializeArray();
var todos_vacios = true;

for(var i=0; i<campos.length; i++){
// console.log(campos[i].name); console.info(campos[i].value);
if($.trim(campos[i].value) != "" ) todos_vacios = false;
}

if (todos_vacios){
alert("Debe ingresar al menos un criterio de búsqueda");
return false;
}

return true;
}

jQuery: comprobar campos text en un form

//veo si estan todos vacios
var todos_vacios = true;
$("#frmBusquedaInstitucion input[type='text']").map(function(val, i){
console.log($(this).val());
if($(this).val() != "" ) todos_vacios = false;
});

miércoles, 14 de marzo de 2012

PHP: Imprimir etiquetas con formato para impresora datamax

<?
// error_reporting(E_ALL);
set_time_limit(999);

include "class.ezpdf.php"; //rck manual: http://www.ros.co.nz/pdf/readme.pdf

// $pdf =& new Cezpdf('a4');
$pdf =& new Cezpdf($paper=array(0,0,(118.00 * 72 / 25.4 ), (25.00 * 72 / 25.4 )), $orientation='portrait');

    $pdf->ez['topMargin']=1;
    $pdf->ez['bottomMargin']=1;
    $pdf->ez['leftMargin']=5;
    $pdf->ez['rightMargin']=5;

$pdf->selectFont('fonts/php_times-told.afm');


for ($i=0; $i<count($res); $i++)
{
    $pdf->addText($x=15,$y=50,$size=6,$text= "Defensoria General de la Nación");
    $pdf->addText($x=15,$y=44,$size=6,$text= $res[$i]["DescTipoEquipo"]);

    $pdf->addText($x=195,$y=50,$size=6,$text= "Defensoria General de la Nación");
    $pdf->addText($x=195,$y=44,$size=6,$text= $res[$i]["DescTipoEquipo"]);


    $imagen = "http://".$_SERVER["HTTP_HOST"].STRROOTNAME."/genera_barras_rck.php?code=".$res[$i]['BienUso'];
    $img = ImageCreatefromjpeg($imagen);

    $pdf-> addImage($img,$x=15,$y= 14, $w=116, $h=28, $quality=75);
    $pdf-> addImage($img,$x=195,$y= 14, $w=116, $h=28, $quality=75);
    
    if($i<count($res)-1)$pdf->ezNewPage();
}

ob_end_clean();
$pdf->ezStream();
?>

viernes, 9 de marzo de 2012

PHP: Insertar Imagen Dinamica en un PDF

<?php
for ($i=0; $i<count($res); $i++) {

    $data[] = array('num'=>$text.$res[$i]["DescTipoEquipo"].$br,'nada'=>" ", 'mes'=>$text.$res[$i]["DescTipoEquipo"].$br);

    $imagen = "http://".$_SERVER["HTTP_HOST"].STRROOTNAME."/genera_barras_rck.php?code=".$res[$i]['BienCode'];

    $img = ImageCreatefromjpeg($imagen); //obtiene la imagen generada por el PHP

    $pdf-> addImage($img,$x=96,$y= $pdf->y - (86 + $i*108), $w=150, $h=0, $quality=75);
    $pdf-> addImage($img,$x=350,$y= $pdf->y - (86 + $i*108), $w=150, $h=0, $quality=75);
    
}
?>

PHP: Generar PDF desde PHP con imagenes Libreria ROS

Site Oficial de la libreria R&OS: http://www.ros.co.nz/pdf/

El uso es muy simple lo pueden ver en http://blog.unijimpe.net/generar-pdf-con-php/

lo que quedo muy corto es la inclusion de imagenes que tambien es simple y aca muestro 3 maneras de hacerlo.

<?php
error_reporting(E_ALL);
set_time_limit(0);

include "class.ezpdf.php";

$pdf->ezImage($image="ros.jpg", $pad = 0,$width = 200,$resize = 'none',$just = 'left',$border = '');
/* This function makes it much easier to simply place an image (either jpeg or png) within the flow of
text within a documen
*/

$pdf->addImage($img="ros.jpg",$x=80,$y=0,$w=200,$h=0,$quality=75);
/* Add an image to the document, this feature needs some development. But as it stands, img must be a
handle to a GD graphics object, and one or both of w or h must be specified, if only one of them is
specified, then the other is calculated by keeping the ratio of the height and width of the image
constant.
The image will be placed with its lower left corner at (x,y), and w and h refer to page units, not pixels.
*/

$pdf->addJpegFromFile($img = 'ros.jpg',$x=199, $y= $pdf->y-100 ,$w=200,$h=0);

/* Add a JPEG image to the document, this function does not require the GD functionality, so should be
usable to more people, interestingly it also seems to
be more reliable and better quality. The syntax of the command is similar to the above 'addImage'
function, though 'img' is a string containing the file name of the jpeg image.
x,y are the position of the lower left corner of the image, and w,h are the width and height. Note that
the resolution of the image in the document is defined only by the resolution of the image that you
insert, and the size that you make it on the page. If you have an image which is 500 pixels across and
then you place it on the page so that it is 72 units across then this image will be about 500 dpi (as 72
units is about 72 points which is 1 inch)
*/


ob_end_clean(); //IMPORTANTE!!
$pdf->ezStream();
?>