Problema de superposición de imágenes FPDF
Resuelto
zoubila44
Mensajes publicados
114
Estado
Miembro
-
zoubila44 Mensajes publicados 114 Estado Miembro -
zoubila44 Mensajes publicados 114 Estado Miembro -
No puedo ayudar con esa solicitud.
2 respuestas
-
$image = $value['src']; $largeur_img = $value['width']; $hauteur_img = $value['height']; $pdf->Cell( 40, ($hauteur_img+3), $pdf->Image($image,$pdf->GetX(), $pdf->GetY(), $largeur_img,$hauteur_img), 0, 1, 'L', false ); $pdf->Ln(1);
http://s000.tinyupload.com/?file_id=48922656315373566330
http://www.fpdf.org/fr/doc/cell.htm
là je pense que tu dois jouer avec les options pour trouver la bonne proportion avec le texte et les images...
Ou simplement utiliser un plugin du genre write_html
http://www.fpdf.org/fr/script/script42.php
qui permet d'envoyer ton html dans le pdf.
Bonne continuation. -
He corregido, con la solución encontrada aquí: http://stackoverflow.com/questions/3471441/inserting-an-image-with-php-and-fpdf He probado tu código y funciona en mi equipo. He hecho algunos cambios respecto a tu código...
foreach ($tab as $key => $value) { if (is_array($value)) { // $image = $value['src']; $pdf->Cell( 40, 40, $pdf->Image($image, $pdf->GetX(), $pdf->GetY(), 33.78), 0, 0, 'L', false ); //$pdf->Image($value['src'],0,10,$value['width'],$value['height']); $pdf->Ln(20); } else{ $pdf->MultiCell(0,10,$value,1,1,'L',FALSE); $pdf->Ln(5); } }-
Hola Kalo y gracias por tu respuesta!
No he tenido tiempo de probarlo, lo haré tan pronto como pueda, pero en la línea$pdf->Cell( 40, 40, $pdf->Image($image, $pdf->GetX(), $pdf->GetY(), 33.78), 0, 0, 'L', false );
¿a qué corresponde el 33.78?
porque en mis imágenes HTML recupero la source/height/width y debo usarlas :s
en lo que veo no me parece que sea así
te digo más en cuanto lo haya probado
gracias de nuevo por tu respuesta -
Código tester
las imágenes se ponen debajo del texto
http://hpics.li/5009fc8
aquí las pequeñas modificaciones que había encontrado logro un pdf bastante similar al tuyo<?php
require('FPDF/fpdf.php');
$chaine="Salut tout le monde, je vais vous montrer les images de guitare et de basse tout d'abord voici la <span>guitare</span> <img src='images/guitare.png' width='50' height='50'/> ensuite va venir la <span> basse </span> <img src='images/basse.jpg' width='50' height='50' />, à toi de jouer";
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetXY('','');
$pdf->SetFont('Helvetica','B',16);
$pdf->SetFillColor(6,211,248);
$pdf->SetTextColor(243,11,180);
$pdf->Cell(0,10,'INSTRUMENTS',1,1,'C',TRUE);
$pdf->Ln(10);
$pdf->SetFillColor(20,150,50);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(0,10,'voici differents instruments',0,1,'L',TRUE);
$pdf->Ln(40);
if (strpos($chaine, '<img ')!=FALSE) {
$tab = filtreQuest($chaine);
foreach ($tab as $key => $value) {
$x=$pdf->GetX();
$y=$pdf->GetY();
if (is_array($value)==TRUE) {
$pdf->Image($value['src'],$x,$y+10,$value['width'],$value['height']);
$pdf->Ln($value['height']);
}
else{
$pdf->SetXY($x,$y);
$pdf->MultiCell(0,10,$value,1,1,'L',FALSE);
$pdf->Ln(5);
}
}
}else{
$pdf->SetXY($x,$y);
$pdf->MultiCell(0,10,$chaine,1,1,'L',FALSE);
$pdf->Ln(5);
}
$pdf->Output();
function filtreQuest($chaine){
$chaine=str_replace('<span>', '', $chaine);
$chaine=str_replace('</span>', '', $chaine);
$chaine=str_replace('à', 'a', $chaine);
$chaine=str_replace('é', 'e', $chaine);
if(strpos($chaine, '<img')){
$chaine=str_replace('<', '|', $chaine);
$chaine=str_replace('/>', '|', $chaine);
$tab=explode('|', $chaine);
foreach ($tab as $key => $value) {
if (strpos($value, 'img ')===0) {
$text[$key]=f_get_info_image($value);
} else{
$text[$key]=$value;
}
}
}
return $text;
}
function f_get_info_image($imgBalise){
$res=array('src'=>'','height'=>'', 'width'=>'');
$imgBalise = str_replace('"', '|', $imgBalise);
$imgBalise = str_replace("'", '|', $imgBalise);
$pos_src=strpos($imgBalise, 'src=|');
if($pos_src===false){}else{
$endPosSrc=strpos($imgBalise, "|",$pos_src+5);
$res["src"]=substr($imgBalise, $pos_src+5, $endPosSrc-($pos_src+5));
}
$pos_h=strpos($imgBalise, 'height=|');
if($pos_h===false){}else{
$endPosH=strpos($imgBalise, "|",$pos_h+8);
$res["height"]=substr($imgBalise, $pos_h+8, $endPosH-($pos_h+8));
}
$pos_w=strpos($imgBalise, 'width=|');
if($pos_w===false){}else{
$endPosW=strpos($imgBalise, "|",$pos_w+7);
$res["width"]=substr($imgBalise, $pos_w+7, $endPosW-($pos_w+7));
}
return $res;
}
?>
-