Bueno, este es el codigo con el que pretendo generar el archivo PDF.... el codigo que he estado mencionando anteriormente es uno de pruebas para verificar el funcionamiento
Código PHP:
function genera_excel(){
global $titulosoftware, $nom_emp, $nit_emp, $a_f, $m_rep, $fecha_i, $fecha_f, $m_det, $rec_tmp, $cod_rep, $tota, $shtml;
$shtml = "<html><body>";
$shtml = "<table border='0' align=center cellspacing='4' cellpadding='0' width=100%>";
$shtml .= "<tr><td colspan=29 align=center>$nom_emp Id.:$nit_emp</td></tr>";
$shtml .= "<tr>";
$fecha_i = $a_f[1];
$fecha_f = $a_f[2];
$cen = trim($rec_tmp[0]['c_costo']);
$c_cto = trim($rec_tmp[0]['c_costo']);
$empre = "[$cen] ".trim($rec_tmp[0]['n_centro']);
$shtml .= "<td colspan=6>Cliente: $empre</td></tr>";
$shtml .= "<tr>";
$titulo = "LIQUIDACION DE NOMINA DESDE $fecha_i HASTA $fecha_f";
$shtml .= "<td colspan=23>$titulo</td></tr>";
$shtml .= "<tr>";
$shtml .= "<td with=200>Trabajador</td>";
$cols = 2;
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") === false) {
$ttt = trim($m_det[$j]["titulo1"]);
$ttt = ereg_replace(" ","_",$ttt);
$shtml .= "<td with=150>$ttt</td>";
}
}
$shtml .= "</tr>";
$nita = -1;
$cena = "";
$pagina = 0;
$k = count($rec_tmp);
$nivel_det = 6;
$c_costo_anterior = $c_cto;
$vincula_anterior = trim($rec_tmp[0]["c25"]);
$n_vincula_anterior = trim($rec_tmp[0]["descripcion"]);
$n_desc_centro = trim($rec_tmp[0]["n_centro"]);
$regis = 0;
$total_vincul = Array();
$total_centro = Array();
foreach ($tota as $key => $xx) {
$total_vincul[$key] = 0;
}
foreach ($tota as $key => $xx) {
$total_centro[$key] = 0;
}
for ($p=$pagina; $p<$k; $p++) {
if ($vincula_anterior != trim($rec_tmp[$p]["c25"])) {
$shtml .= "<tr>";
$var = "TOTAL $n_vincula_anterior";
$shtml .= "<td colspan=3>". $var."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$va1 = $total_vincul[$j+1];
$total_centro[$j+1] += $total_vincul[$j+1];
$var= number_format($va1, 2, '.', ',');
$shtml .= "<td align=right>$var</td>";
}
$vincula_anterior = trim($rec_tmp[$p]["c25"]);
$n_vincula_anterior = trim($rec_tmp[$p]["descripcion"]);
$regis = 0;
$total_vincul = Array();
foreach ($tota as $key => $xx) {
$total_vincul[$key] = 0;
}
}
if ($c_costo_anterior != trim($rec_tmp[$p]["c_costo"])) {
$shtml .= "<tr bgcolor=lightcyan>";
$var = "TOTAL $n_desc_centro";
$shtml .= "<td colspan=3>". $var."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$va1 = $total_centro[$j+1];
$var= number_format($va1, 2, '.', ',');
$shtml .= "<td align=right>$var</td>";
}
$c_costo_anterior = trim($rec_tmp[$p]["c_costo"]);
$n_desc_centro = trim($rec_tmp[$p]["n_centro"]);
$regis = 0;
$total_centro = Array();
foreach ($tota as $key => $xx) {
$total_centro[$key] = 0;
}
$cen = trim($rec_tmp[$p]['c_costo']);
$empre = "[$cen] ".trim($rec_tmp[$p]['n_centro']);
$shtml .= "<tr bgColor=#CBD9E5>";
$shtml .= "<td colspan=23 ALIGN=left><b>Cliente: $empre</td>";
}
$regis++;
$datos = $rec_tmp[$p];
$niv = $datos['nivel_det'];
$llave = trim($datos['llave']);
if ($niv>$nivel_det) {
$k++;
if ($k > count($rec_tmp))
$k = count($rec_tmp);
continue;
}
$shtml .= "<tr>";
if (strlen(trim($datos['llave'])) > 0)
$cuenta = round(trim($datos['llave']));
else
$cuenta = "";
$shtml .= "<td align='right'>$cuenta</td>";
$shtml .= "<td align='left' colspan=2 width=36>". $datos['n_llave']."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$col = $m_det[$j]['col_rep'];
$tipo_campo = $m_det[$j]['tipo_campo'];
$campo = "c$col";
$va1 = trim($datos[$campo]);
$sor = trim($m_det[$j]['formato']);
if (!is_numeric($sor)|| strlen(trim($m_det[$j]))==0)
$sor = 2;
if (is_numeric($va1)) {
$total_vincul[$col] += $va1;
$var= number_format($va1, $sor, '.', ',');
}
else
$var = $va1;
if (is_numeric($va1))
$shtml .= "<td align=right>$var</td>";
else
$shtml .= "<td align=left>$var</td>";
}
$p = 50000000;
}
$shtml .= "<tr bgcolor=lightcyan>";
$var = "TOTAL $n_vincula_anterior";
$shtml .= "<td colspan=3>". $var."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$va1 = $total_vincul[$j+1];
$total_centro[$j+1] += $total_vincul[$j+1];
$var= number_format($va1, 2, '.', ',');
$shtml .= "<td align=right>$var</td>";
}
$shtml .= "<tr bgcolor=lightcyan>";
$var = "TOTAL $n_desc_centro";
$shtml .= "<td colspan=3>". $var."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$va1 = $total_centro[$j+1];
$var= number_format($va1, 2, '.', ',');
$shtml .= "<td align=right>$var</td>";
}
$shtml .= "<tr bgcolor=lightcyan>";
$var = "GRAN TOTAL Regs:".count($rec_tmp);
$shtml .= "<td colspan=3>". $var."</td>";
for ($j=0; $j<count($m_det); $j++) {
if (strpos($m_det[$j]['formato'],"-") !== false)
continue;
$va1 = $tota[$j+1];
$var= number_format($va1, 2, '.', ',');
$shtml .= "<td align=right>$var</td>";
}
$shtml .= "</tr>";
$shtml .= "</td></tr>";
$shtml .= "</td>";
$shtml .= "</tr>";
$shtml .= "</table>";
$shtml .= "</body></html>";
$pd = genera_pdf1($shtml);
}
function genera_pdf1($shtml) {
require_once("./html2fpdf.php");
ob_end_clean();
$pdf=new HTML2FPDF("L","mm",array(416,556));
$pdf->AddPage("L",array(416,556));
$pdf->SetFontSize(8);
$pdf->WriteHTML($shtml);
$pdf->Output('archivo_pdf.pdf','D');
}
Como digo, este es el codigo de mi script que estoy desarrollando, el anterior es solo de prueba.
Conm este codigo al hacer un echo $shtml muestra la tabla en el navegador perfecto, no siendo asi al generar el archivo en PDF
Mil Gracias de antemano por sus aportes
Un Cordial Saludo