Как я могу использовать код html в нижнем колонтитуле DOM PDF? - PullRequest
0 голосов
/ 07 августа 2020

Вот как я создаю нижний колонтитул с помощью DOMPdf:

$canvas = $dompdf->get_canvas();
$footer = $canvas->open_object();
$w = $canvas->get_width();
$h = $canvas->get_height();
$canvas->page_text($w-85,$h-28,"footer right",'helvetica',8);
$canvas->page_text($w-320,$h-28,"Page {PAGE_NUM} of {PAGE_COUNT}",'helvetica',8);
$canvas->page_text($w-550,$h-28,"footer left", 'helvetica',8);

Это создает 3 раздела в моем нижнем колонтитуле, что мне подходит. Но мне нужна возможность в каждую строку интегрировать html текст. Пробовал вот так:

    $canvas->page_text($w-85,$h-28,"<b>My Company</b><br>My street<br>My city",'helvetica',8);
    $canvas->page_text($w-320,$h-28,"Page {PAGE_NUM} of {PAGE_COUNT}",'helvetica',8);
    $canvas->page_text($w-550,$h-28,"footer left", 'helvetica',8);

Но код html в pdf не конвертируется.

Еще пробовал:

$text = $dompdf->loadHtml("<b>My Company</b><br>My street<br>My city");
$canvas->page_text($w-85,$h-28,$test,'helvetica',8);

Ничего подобного загружается

Ответы [ 2 ]

1 голос
/ 07 августа 2020

Вы не можете добавить код html в DomPdf

Но вы можете обойтись, используя css

             footer {
                position: fixed; 
                bottom: 0; 
                left: 0px; 
                right: 0px;
                height: 20px; 
                border-top: 1px solid #AAAAAA;
                color: #777777;
                width: 100%;
                padding: 8px 0;
                text-align: center;
            }

И в html body поместите свой контент в <footer> </footer>

0 голосов
/ 07 августа 2020

Рабочий пример:

<html>
<head>
    <style>
    @page { margin: 180px 50px; }
    #header { position: fixed; left: 0px; top: -180px; right: 0px; height: 150px; background-color: orange; text-align: center; }
    #footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; background-color: lightblue; }
    #footer .page:after { content: counter(page, upper-roman); }
    </style>
<body>
    <div id="header">
    <h1>Widgets Express</h1>
    </div>
    <div id="footer">
    <p class="page">Page </p>
    </div>
    <div id="content">
    <p>the first page</p>
    <p style="page-break-before: always;">the second page</p>
    </div>
</body>
</html> 
...