pdf-l4
pdf-l4 copied to clipboard
PDF not generating in loop
I am trying to generate multiple pdf but it showing me error:
{"error":{"type":"DOMPDF_Exception","message":"No block-level parent found. Not good.","file":"/var/www/crm/vendor/dompdf/dompdf/include/inline_positioner.cls.php","line":37}}
Are you sur you're using my package ?
Mine includes dompdf directly inside.
Something that worked for me is to just add the line
$this->dompdf = new \DOMPDF();
before loading the html in the load() function. This will recreate the DOMPDF object each time, thus removing the block-level error when creating several PDF's per request.
hi! thujohn I'm using your dompdf package and i'm getting the same error, can you give some ideas to fix it??
Hi.
Have you seen this comment ? https://github.com/thujohn/pdf-l4/issues/22#issuecomment-28437889
yes, i have, and it works!! thank you.
Hi again, thujohn i'm trying to generate a pdf file but i don't know why it does not work but it does not give any error message either!!! this is de code:
public function Mensual($idPlanilla,$renglon,$nombreCarpeta){ $enLetras = new EnLetras(); $planilla = new modeloPlanilla(); $detalle = new mdlDetallePlanillaEmpleado(); $varios = new Varios(); $banco = new BancoEmpleado(); $mes = 1;//date("m"); $anio = date("Y"); $mesLetras = $enLetras->MesLetras($mes); $hoy = date("dmY");
//encabezado del voucher
$titulo = "PROCURADOR DE LOS DERECHOS HUMANOS<br>BOLETA DE LIQUIDACIÓN DE SUELDO<br>".strtoupper($mesLetras)." DEL ".$anio;
//var_dump($titulo); exit(1);
$listaEmpleados = $planilla->getEmpleadosVoucher($idPlanilla,$renglon);
$fechaPlanilla = $planilla->getFecha($idPlanilla);
//echo count($listaEmpleados);
//var_dump($listaEmpleados); exit(1);
$texto = "";
$nombre = "voucher_".$hoy."_".$renglon.".pdf";
$nombrepdf = $nombreCarpeta."/".$nombre;//x
//echo $nombre." ".$nombrepdf;
$texto = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body>";
$contador = 0;
echo "a punto";
foreach($listaEmpleados as $empleado){ //$empleado->id es el idPlanillaEmpleado, con el que busco el detalle
echo "empleado";
//var_dump($empleado);
$datosbanco = $banco->getBanco($empleado->empleado_id);
//var_dump($datosbanco); exit(1);
$texto .= "<div style=\"font-family:Arial, Helvetica, sans-serif; font-size:8pt; page-break-after:always\"><table align=\"center\" width=\"85%\"><tr><td colspan=\"2\"><table width=\"100%\"><tr><td><img src=\"images/logo.PNG\" width=\"167\" height=\"83\" /></td><td align=\"center\"><strong>".$titulo."</strong></td></tr></table></td></tr>";
$texto .= "<tr><td colspan=\"2\"> </td></tr>";
$texto .= "<tr><td align=\"left\">NOMBRE:".$empleado->nombre_empleado."</td><td>CARGO: ".$empleado->Puesto."</td></tr>";
$texto .= "<tr><td colspan=\"2\">PARTIDA: $empleado->partida_presupuestaria<br>".$empleado->pg."-".$empleado->sp."-".$empleado->py."-".$empleado->act."-".$empleado->obr."-".$empleado->ren."-".$empleado->ubg."-".$empleado->fte."-".$empleado->org."-".$empleado->corr."</td></tr>";
$texto .= "<tr><td colspan=\"2\">NIT: ".$empleado->nit."</td></tr>";
$texto .= "<tr><td colspan=\"2\">FECHA: ".$enLetras->FechaLetras($fechaPlanilla[0]['Generada_at'])."</td></tr>";
$texto .= "<tr><td colspan=\"2\">DIAS LABORADOS: ".$empleado->dias_laborados."</td></tr><tr><td colspan=\"2\"> </td></tr>";
$texto .= "<tr><td colspan=\"2\" align=\"center\"><table width=\"90%\"><tr><td colspan=\"2\" align=\"left\"><strong>ASIGNACIONES</strong></td></tr>";
$asignaciones = $detalle->getDetallePagoIn($empleado->id);
//var_dump($asignaciones); exit(1);
foreach($asignaciones as $pago){
$texto .= "<tr><td>".$pago->Nombre."</td><td>Q. ".number_format($pago->Monto,2)."</td></tr>";
}
$texto .= "</table></td></tr>";
$texto .= "<tr><td align=\"center\"><table width=\"90%\">";
$texto .= "<tr><td colspan=\"2\" align=\"left\"><strong>DESCUENTOS</strong></td></tr>";
$descuentos = $detalle->getDetallePagoOut($empleado->id);
foreach($descuentos as $pago){
$texto .= " <tr><td>".$pago->Nombre."</td><td>Q. ".number_format($pago->Monto,2)."</td></tr>";
}
$texto .= "</table></td></tr><tr><td> </td></tr>";
$total = $detalle->getTotal($empleado->id);
$texto .= "<tr><td colspan=\"2\" align=\"left\"><strong>TOTAL A RECIBIR: Q.".number_format($total[0]['Monto'],2)."</strong> En letras: ".strtoupper($enLetras->ValorEnLetras(round($total[0]['Monto'],2),"quetzales con"))."**<br /><br />Líquido acreditado en ".$datosbanco[0]['Nombre']." en su cuenta número ".$datosbanco[0]['NumeroCuenta']."</td></tr>"; //echo $texto; exit(1);
$texto .= "<tr><td colspan=\"2\" align=\"center\">RECIBÍ DE CONFORMIDAD EL IMPORTE NETO INDICADO Y ACEPTO ESTA LIQUIDACIÓN, LA CUAL CUBRE LA TOTALIDAD DE LA ASIGNACIÓN DURANTE EL PERÍODO A QUE SE REFIERE.</td></tr>";
$texto .= "<tr><td colspan=\"2\" align=\"left\"><table width=\"90%\"> <tr><td>Vo.Bo.<img src=\"images/firma_pineda.png\" width=\"150\" height=\"82\" /><br />LIC. OSCAR FRANCISCO PINEDA GARAY<br>DIRECTOR FINANCIERO<br />PROCURADOR DE LOS DERECHOS HUMANOS</td><td>Recibí conforme:</td></tr></table></td></tr></table></div>";
$contador = $contador + 1;
}
$texto .= "</body></html>";
$contador = $contador + 1;
//echo $texto;
\File::put($nombrepdf, \PDF::load($texto, 'A4', 'portrait')->output());
$voucher = array(
'planilla_id' => $idPlanilla,
'Ubicacion' => $nombrepdf,
'NombreEmpleado' => '',//$empleado->nombre_empleado,
'PartidaPresupuestaria' => ''//$empleado->partida_presupuestaria
);
$id = PlanillaVoucher::NuevoVoucher($voucher);
}
thanks!