0

Using wkhtmltopdf 0.12.6 and mikehaertl's phpwkhtmltopdf I'm trying to add a header and footer to each page while setting the header and footer spacing. This used to work when using an older binary file, but we recently switched to 0.12.6 installed on the server. The server is running on AlmaLinux 8.7.

Creating the file:

$pdf_options = array(
    'load-error-handling' => 'ignore',
    'ignoreWarnings'=> true,
    'enable-javascript',
    'dpi' => '300',
    'no-outline',
    'margin-bottom' => '0mm',
    'margin-top' => '0mm',
    'margin-left' => '0mm',
    'margin-right' => '0mm',
    'header-html' => '/path/to/header.html',
    'footer-html' => '/path/to/footer.html',
    'header-spacing' => 20,
    'footer-spacing' => 15,
);
$pdf = new Pdf($pdf_options);
$pdf->addPage($html);
$pdf->send('pdf.pdf');

Expected output: Expected output

Given output Given output

As you can see, the spacing is lost and there is no header or footer. What can cause the issue?

  • How is the styling applied, inline CSS or external CSS files? If external the CSS might not be loaded. Just a guess though. – cOle2 Mar 07 '23 at 17:39
  • This is not related to the CSS styling, which is all inline. It turns out that when the margin-bottom and margin-top in the PDF options are set, it does work. – InsurgentNL Mar 08 '23 at 09:59

1 Answers1

1

Found the solution myself after fiddling around. Setting the header-spacing and footer-spacing without the margin-top and margin-bottom does not work. Applying both options makes it work. Also setting just the margin puts the header over of the real text and not above it.