Código PHP:
$pdf=new FPDF('L','cm','legal');
$pdf->SetMargins(1,1,1);
$pdf->AddPage('L');
$pdf->SetFont('Arial','',10);
$pdf->SetFillColor(200);
$pdf->Cell(23,1,'Digital Documents',0,0,'L');
$pdf->Cell(8,1,"Direct Image 2.5",0,0,'R');
$pdf->Ln(1);
$pdf->Cell(31,1,'PLANILLA RESULTADO BUSQUEDA',0,0,'C');
$pdf->Ln(1);
$pdf->Cell(10,0.5,"Cliente",1,0,'C',1);
$pdf->Cell(9,0.5,"Departamento",1,0,'C',1);
$pdf->Cell(9,0.5,"Doc. Buscado",1,0,'C',1);
$pdf->Cell(3,0.5,"Encontrados",1,0,'C',1);
$pdf->Ln();
$pdf->Cell(10,1,"$cliente",1,0,'C');
$pdf->Cell(9,1,"$iddepto",1,0,'C');
$pdf->Cell(9,1,"$idtipo",1,0,'C');
$pdf->Cell(3,1,"$bus",1,0,'C');
$pdf->Ln(1.5);
$cont=0;
foreach ($bus as $indice=>$valor)
{
$dato."=>".$indice."";
if (!empty($valor))
{
$SQLcona="SELECT * FROM adoc where estado='1' and tipodoc='$idtipo' and nombre='$indice' and valor like '%$valor%'";
$cona = pg_query($IdConexion,$SQLcona);
While($regi=pg_fetch_array($cona))
{
$id_bus[]="$regi[documento]";
}
$cont++;
$cua=0;$valida=0;
foreach ($id_bus as $indice=>$valor)
{
$cua++;
if($year!='' and $mes!='' and $cajab==''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and year='$year' and mes='$mes' order by caja,year,mesn";}
if($year!='' and $mes=='' and $cajab==''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and year='$year' order by caja,mesn";}
if($year=='' and $mes!='' and $cajab==''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and mes='$mes' order by caja,year";}
if($year=='' and $mes=='' and $cajab==''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' order by caja,year,mesn";}
if($year!='' and $mes!='' and $cajab!=''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and caja='$cajab' and year='$year' and mes='$mes' order by caja,year,mesn";}
if($year!='' and $mes=='' and $cajab!=''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and caja='$cajab' and year='$year' order by caja,year,mesn";}
if($year=='' and $mes!='' and $cajab!=''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and caja='$cajab' and mes='$mes' order by caja,year,mesn";}
if($year=='' and $mes=='' and $cajab!=''){$SQLsina="SELECT * FROM documento where estado='1' and cliente='$idcliente' and tipo='$idtipo' and iddocumento='$valor' and caja='$cajab' order by caja,year,mesn";}
$sina = pg_query($IdConexion,$SQLsina) or die(pg_error());
$NFilasd = pg_num_rows($sina);
if($NFilasd==0)
{
$valida++;
if($cua==$valida)
{
//echo "<tr bgcolor='ffffff' align='center'><td><font face='Arial, Helvetica, sans-serif' size='2'><b>No posee $nomtipo asociados</b></td></tr>";
//die();
}
}
else
{
$yeare=date("Y");$mese=date("m");
$SQLres="SELECT * FROM atipo where estado='1' and documento='$tipodoc'";
$res = pg_query($IdConexion,$SQLres) or die(pg_error());
$Encontro = pg_num_rows($res);
if($cua==1)
{
$pdf->Cell(7,0.5,'Tipo',1,0,'C',1);
$pdf->Cell(4,0.5,'Caja',1,0,'C',1);
$pdf->Cell(5,0.5,'Periodo',1,0,'C',1);
$pdf->Cell(5,0.5,'Sub-Periodo',1,0,'C',1);
$pdf->Cell(3,0.5,'Año',1,0,'C',1);
$pdf->Cell(4,0.5,'Expira',1,0,'C',1);
$pdf->Cell(3,0.5,'Hojas',1,0,'C',1);
if($Encontro!=0)
{
if ($re= pg_fetch_array($res))
{
DO
{
$pdf->Cell(5,0.5,'$re[nombre]',1,0,'C',1);
}
WHILE ($re=pg_fetch_array($res));
}
}
}
$pdf->Ln();
While($row=pg_fetch_array($sina))
{
$pdf->Cell(7,0.5,"$row[tipo]",1,0,'L');
$pdf->Cell(4,0.5,"$row[caja]",1,0,'C');
$pdf->Cell(5,0.5,"$row[periodo]",1,0,'C');
if("$row[mes]"=='No Figura'){$mes='-';}else{$mes="$row[mes]";}
$pdf->Cell(5,0.5,"$mes",1,0,'C');
$pdf->Cell(3,0.5,"$row[year]",1,0,'C');
if("$row[expira]"==0){$expira='Indef.';}else{$expira="$row[expira]";}
$pdf->Cell(4,0.5,"$expira",1,0,'C');
$pdf->Cell(3,0.5,"$row[hojas]",1,0,'C');
$sqlad="SELECT * FROM adoc where documento='$row[iddocumento]'";
$res=pg_query($IdConexion,$sqlad);
$Encontro = pg_num_rows($res);
if($Encontro==2)
{
if ($re= pg_fetch_array($res))
{
DO
{
$pdf->Cell(4,0.5,"$re[valor]",1,0,'L');
}
WHILE ($re=pg_fetch_array($res));
}
}
if($Encontro==1)
{
if ($re= pg_fetch_array($res))
{
DO
{
$pdf->Cell(4,0.5,"$re[valor]",1,0,'L');
$pdf->Cell(4,0.5,"",1,0,'L');
}
WHILE ($re=pg_fetch_array($res));
}
}
if($Encontro==0)
{
$pdf->Cell(8,0.5,"-",1,0,'C');
}
$pdf->Ln();
}
}
}
}
}
$pdf->Ln();
$pdf->Cell(8,0.5,"Fecha",1,0,'C',1);
$pdf->Cell(8,0.5,"Hora",1,0,'C',1);
$pdf->Cell(15,0.5,"Responsable",1,0,'C',1);
$pdf->Ln();
$pdf->Cell(8,1,"$fecha",1,0,'C');
$pdf->Cell(8,1,"$hora",1,0,'C');
$pdf->Cell(15,1,"$user",1,0,'C');
$pdf->Output();