spiritix / php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome
MIT License
112 stars 29 forks source link

pageNumber and totalPages are not displayed in footerTemplate #66

Closed riatw closed 7 months ago

riatw commented 8 months ago

Please check the title. How can I resolve this?

code

use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\EmbedOutput;

$input = new UrlInput();
$input->setUrl($requestTmplUrl);

$converter = new Converter($input, new EmbedOutput());

$footerTemplate = <<<END
<div style="font-family: '游ゴシック体', 'Yu Gothic', YuGothic, 'ヒラギノ角ゴ Pro', 'Hiragino Kaku Gothic Pro', 'メイリオ', 'Meiryo', sans-serif; position: relative; margin: 0.5cm 1cm; font-size: 9px; width: 100%;">
  <div style="position: absolute; left: 0; top: 0.5cm;">Site Title</div>
  <div style="position: absolute; width: 100%; top: 0.5cm; text-align: center;">
    <span class="pageNumber"></span> / <span class="totalPages"></span>
  </div>
  <div style="position: absolute; right: 0; top: 0.5cm;">$footerRight</div>
</div>
END;

$converter->setOptions([
    'printBackground' => true,
    'displayHeaderFooter' => true,
    'margin' => array('top' => '1cm','right' => '1cm','bottom' => '0cm','left' => '1cm',),
    'footerTemplate' => $footerTemplate,
]);

$output = $converter->convert();
$output->embed($title . ".pdf");
SmurfVal commented 7 months ago

We ran into the same issue: Turns out our default size was so small, we thought it wasn't rendering.
Also had to increase the bottom margin as maybe there isn't enough space inside of it to render the html Screenshot 2024-04-08 at 12 27 48

spiritix commented 7 months ago

Thanks guys. I will add that to the manual.

riatw commented 7 months ago

@SmurfVal @spiritix thank you for your reply.

Increasing the font size did not solve the problem here. Is it possible for you to tell me which version and settings you tried?

Only pageNumber and totalPages are not drawn, but normal text is drawn.