简体   繁体   中英

Empty PDF's with Dompdf

I am making an integration of invoices to a wordpress site, in which I have to generate a pdf of the invoices that are stamped, so several PDF's have to be done at the same time, so in a foreach cycle I am making the call of the class I did with dompdf, in my tests I am trying to generate 9 PDF's at a time, and the files are created correctly, but the detail is that only the first PDF has content, the other 8 PDF's are empty, some will have an idea of what pass? Here I leave the code

class genera_pdf{
 public function genera($path){
        $fechaHoy= date( 'Y-m-d');
        ob_start();
        require_once plugin_dir_path(__DIR__) . 'templates/pdf/factura.php';
        $codigoHTML=ob_get_clean();
        $pdf= new Dompdf();
        $pdf->load_html($codigoHTML);
        $pdf->setPaper('A4', 'portrait');
        $pdf->render();
        $salida = $pdf->output()
        file_put_contents($path['basedir'].'/profact/FacturaRetenciones-'.$fechaHoy.'.pdf', $salida);
    }
}

I already solved it, the problem was with the line:

require_once plugin_dir_path (__ DIR__). 'templates / pdf / invoice.php';

Since it requires_once, it includes the file only if it was not included before, as in the first route of the cycle it had already been included, the following ones did not already do it and as everything was saved in the buffer with ob_get_clean (), at the same time it is deleted at the end, that's why it was completely blank, all I did was change to:

include (plugin_dir_path (__ DIR__). 'templates / pdf / invoice.php');

With that my problem was solved and all the PDF's already have the content I wanted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM