pdf-l4 icon indicating copy to clipboard operation
pdf-l4 copied to clipboard

PDF not generating in loop

Open jitendrathakur opened this issue 10 years ago • 6 comments

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}}

jitendrathakur avatar May 27 '14 12:05 jitendrathakur

Are you sur you're using my package ?

Mine includes dompdf directly inside.

thujohn avatar May 27 '14 20:05 thujohn

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.

imevul avatar Jun 12 '14 00:06 imevul

hi! thujohn I'm using your dompdf package and i'm getting the same error, can you give some ideas to fix it??

ligiama avatar Jun 19 '14 15:06 ligiama

Hi.

Have you seen this comment ? https://github.com/thujohn/pdf-l4/issues/22#issuecomment-28437889

thujohn avatar Jun 19 '14 17:06 thujohn

yes, i have, and it works!! thank you.

ligiama avatar Jun 19 '14 18:06 ligiama

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&Oacute;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\">&nbsp;</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\">&nbsp</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>&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;En letras: ".strtoupper($enLetras->ValorEnLetras(round($total[0]['Monto'],2),"quetzales con"))."**<br /><br />L&iacute;quido acreditado en ".$datosbanco[0]['Nombre']." en su cuenta n&uacute;mero ".$datosbanco[0]['NumeroCuenta']."</td></tr>"; //echo $texto; exit(1);
        $texto .= "<tr><td colspan=\"2\" align=\"center\">RECIB&Iacute; DE CONFORMIDAD EL IMPORTE NETO INDICADO Y ACEPTO ESTA LIQUIDACI&Oacute;N, LA CUAL CUBRE LA TOTALIDAD DE LA ASIGNACI&Oacute;N DURANTE EL PER&Iacute;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&iacute; 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!

ligiama avatar Apr 17 '15 20:04 ligiama