How do I get the right CSS in DOMPDF?

Asked

Viewed 834 times

-1

Good morning Guys, all right?

I have 3 files: certificate.png | style.css | Certificate.html

I have a method that binds them and PDF the certificate, when printing on the screen with var_dump comes out right, when generating the pdf leaves the first sheet blank, second half of the image and the third with the descriptions, and instead of printing in landscape that is set, He printed it in portrait, what could it be? has some scheme for DOMPDF to get the correct css?

follows method that joins the files and makes the call of pdf creation


  public function generateCertificate(){
        $this->load->library('CertificatePDF');
        $certificantePDF = new CertificatePDF();
        $html = file_get_contents('assets/components/certificate/certificate.html');

        $keys = array('[[SITE_URL]]');
        $values = array(site_url('assets/components/certificate'));

        $html = str_replace($keys, $values, $html);

        $filename = "certificado" . date('YmdHis');
        $dir = 'assets/download/certificados/';
        $download = true;
        $certificantePDF->createPdfFromHtml($html, $filename, $dir, $download);

        var_dump($html);
    }


Method that generates PDF


use Dompdf\Dompdf;
use Dompdf\Options;

require_once(__DIR__ . "/../../assets/components/dompdf/autoload.inc.php");

class CertificatePDF {

    public function createPdfFromHtml($html, $filename, $dir, $download = false) {
        $option = new Options();
        $option->set(array(
            'isPhpEnabled' => true,
            'isRemoteEnabled' => true,
            'isHtml5ParserEnabled' => true
        ));
        $dompdf = new Dompdf($option);
        $dompdf->set_paper('A4', 'landscape');
        $dompdf->load_html($html);
        $dompdf->set_base_path(__DIR__ . "/../../");

        $dompdf->render();
        if ($download) {
            $dompdf->stream($filename . ".pdf");
        }
        file_put_contents($dir . $filename . ".pdf", $dompdf->output());
    }

}

1 answer

0

Try applying Landscape to css like this:

@media print{@page {size: landscape}}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.