Dompdf, load stylesheet link

Asked

Viewed 314 times

-2

I’m trying to carry the <link type="text/css" rel="stylesheet" href="https://www.aaaa.dev/assets/css/imprimir-mod-1.css"> but is not loaded when PDF is generated.

If I open the page without generating the PDF it loads the CSS correctly.

What I need to do?

<?php
session_start();
ini_set('memory_limit', '1024M');
$MM_authorizedUsers = 'a';
include __DIR__ . '/../config.php';
include __DIR__ . '/../../permissao.php';

$rs = $mysqli->query("SELECT * FROM aaaa WHERE id = '".$_GET['id']."' && a = '".$_SESSION['a']."'");
$row = $rs->fetch_assoc();

ob_start();
?>

    <!doctype html>
    <html lang="pt-br">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Codigo <?= $row['codigo'] ?></title>
        <link type="text/css" rel="stylesheet" href="https://www.aaaa.dev/assets/css/imprimir-mod-1.css">
    </head>
    <body>

    <table class="w100p space">
        <tr>
            <th>Logo</th>
            <th></th>
            <th>Codigo:</th>
        </tr>
    </table>


    <table class="w100p space left">
        <tr>
            <th>CLIENTE</th>
            <th>LOCAÇÃO</th>
        </tr>
    </table>


    <table class="w100p space left borda" >
        <tr>
            <th>DESCRIÇÃO</th>
            <th>DIAS</th>
            <th>VALOR</th>
            <th>TOTAL</th>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td colspan="4" align="right">
                <table class="totals borda">
                    <tr>
                        <td class="w200p">TOTAL DA FATURA</td>
                        <td class="w200p">R$ 0,00</td>
                    </tr>
                    <tr>
                        <td>DESCONTO</td>
                        <td>R$ 0,00</td>
                    </tr>
                    <tr>
                        <td>DEPÓSITO</td>
                        <td>R$ 0,00</td>
                    </tr>
                    <tr>
                        <td>TOTAL A PAGAR</td>
                        <td>R$ 0,00</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>



    </body>
    </html>

<?php
//exit;
$html = ob_get_clean();
require __DIR__ . '/../../../vendor/autoload.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$arquivo = "Codigo ".$row['codigo'].".pdf";

$dompdf->stream($arquivo, array("Attachment" => false));
?>

1 answer

1

Hello, to reference a CSS file in DOMPDF, you should mention the full file path, try href="https://seusite.com/./../../assets/css/imprimir-mod-1.css or the desired path.

  • Douglas, had done the test only via html and opened, but now when I went to generate the PDF has not yet loaded the CSS. I put the direct link as informed.

  • In this CSS file you only have style settings? or at some point you are referencing there is an image? I use DOMPDF also, and to upload CSS files, I only had to do what’s in the answer, but if it’s remote images, you need to do more things...

  • 1

    CSS only, see https://jsfiddle.net/5cs3koja/

  • Try referencing down, like this: $dompdf->load_html('<link type="text/css" rel="stylesheet" href="https://www.aaaa.dev/assets/css/imprimir-mod-1.css">&#xA;&#xA; '. $html .'&#xA;&#xA; ');

  • It also doesn’t work :( desisto...rsrs, I lost 1/2 day, trying to find a solution.

  • It has something to do, I’m testing on localhost

  • Give up no man, I also broke my head a little to customize my PDF reports using DOMPDF, anything, try to download other versions, look for ready examples, etc...

  • Which version?

  • Man if I’m not mistaken, I used Celke hahaha’s... link

Show 4 more comments

Browser other questions tagged

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