Foros del Web » Programando para Internet » PHP »

Imagenes en pdf con dompdf

Estas en el tema de Imagenes en pdf con dompdf en el foro de PHP en Foros del Web. Hola a todos: Estoy realizando un codigo en el cual genero un pdf con la libreria de dompdf, paso datos y genera bien el pdf, ...
  #1 (permalink)  
Antiguo 20/01/2014, 09:56
 
Fecha de Ingreso: febrero-2011
Mensajes: 195
Antigüedad: 13 años, 2 meses
Puntos: 1
Imagenes en pdf con dompdf

Hola a todos:

Estoy realizando un codigo en el cual genero un pdf con la libreria de dompdf, paso datos y genera bien el pdf, el problema esta en que cuando quiero poner una imagen y redimensionarla solamente me sale el espacio de la imagen pero no la imagen, este es mi codigo para generar el pdf


Código PHP:
$strHTML="imagen<br>
<img src=\"pruebaimg/imagen2.php?imagen=URL_de_la_imagen\" />
<br>termina imagen"
;

require_once(
"pdf/dompdf-0.5.1/dompdf_config.inc.php");

$dompdf=new DOMPDF();
$dompdf->load_html($strHTML);
$dompdf->render();
$dompdf->stream("FichaPDF.pdf");
exit(
0); 
el codigo de imagen2.php es este

Código PHP:
include("resize.php");
    
$imagen=$_GET['imagen'];
    
$thumb=new thumbnail($imagen);
    
$thumb->size_width(180);
    
$thumb->show(); 
y el codigo de resize.php es este

Código PHP:
class thumbnail
{
    var 
$img;

    function 
thumbnail($imgfile)
    {
        
//detect image format
//detect image format | deprecated way //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
#        $this->img["format"]=end(explode(".",$imgfile));
#        $this->img["format"]=strtoupper($this->img["format"]);

        
$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
        
$this->img["format"]=strtoupper($this->img["format"]);
        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
            
$this->img["format"]="JPEG";
            
$this->img["src"] = ImageCreateFromJPEG ($imgfile);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
$this->img["format"]="PNG";
            
$this->img["src"] = ImageCreateFromPNG ($imgfile);
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
$this->img["format"]="GIF";
            
$this->img["src"] = ImageCreateFromGIF ($imgfile);
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
$this->img["format"]="WBMP";
            
$this->img["src"] = ImageCreateFromWBMP ($imgfile);
        } else {
            
//DEFAULT
            
echo "Not Supported File";
            exit();
        }
        @
$this->img["lebar"] = imagesx($this->img["src"]);
        @
$this->img["tinggi"] = imagesy($this->img["src"]);
        
//default quality jpeg
        
$this->img["quality"]=75;
    }

    function 
size_height($size=100)
    {
        
//height
        
$this->img["tinggi_thumb"]=$size;
        @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
    }

    function 
size_width($size=100)
    {
        
//width
        
$this->img["lebar_thumb"]=$size;
        @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
    }

    function 
size_auto($size=100)
    {
        
//size
        
if ($this->img["lebar"]>=$this->img["tinggi"]) {
            
$this->img["lebar_thumb"]=$size;
            @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
        } else {
            
$this->img["tinggi_thumb"]=$size;
            @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
         }
    }

    function 
jpeg_quality($quality=75)
    {
        
//jpeg quality
        
$this->img["quality"]=$quality;
    }

    function 
show()
    {
        
//show thumb
        
@Header("Content-Type: image/".$this->img["format"]);

        
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
            @
imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
#imageJPEG($this->img["des"],"$save",$this->img["quality"]);        
    
imageJPEG($this->img["des"],"",$this->img["quality"]);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
imagePNG($this->img["des"]);
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
imageGIF($this->img["des"]);
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
imageWBMP($this->img["des"]);
        }
    }

    function 
save($save="")
    {
        
//save thumb
        
if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]);
        
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
            @
imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
            
imageJPEG($this->img["des"],"$save",$this->img["quality"]);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
imagePNG($this->img["des"],"$save");
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
imageGIF($this->img["des"],"$save");
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
imageWBMP($this->img["des"],"$save");
        }
    }

  #2 (permalink)  
Antiguo 20/01/2014, 15:44
 
Fecha de Ingreso: febrero-2011
Mensajes: 195
Antigüedad: 13 años, 2 meses
Puntos: 1
Respuesta: Imagenes en pdf con dompdf

Alguien que me ayude??

Etiquetas: dompdf, html, imagenes, pdf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:55.