I'm using wkhtmltopdf
to generate my pdf files. I've left the generation alone for some time and for whatever reason it's not generating the header and footer anymore.
Things I've tried so far (will update this when more answers come in):
- Having the
doctype
,html
,head
andbody
tags ion the header and footer - Chaning the paths to the header and footer to absolute paths (Even using complete absolute paths from the drive forward C:/xampp... does not work.) It might be worth pointing out that changing the filename to something that doesn't exist does not throw an error. So I don't know if it finds the files. Maybe someone can tell me a good way to test this?
This is my header file:
<!DOCTYPE html>
<html>
<head>
<title>PDF header</title>
<style>
html {
display: block;
}
body {
font-family: Calibri, "Segoe Ui Regular", sans-serif;
letter-spacing: 0px;
}
</style>
</head>
<body style="padding-top: 30px">
<img src="../../images/logo_extra.jpg" style="width: 100%;"/>
</body>
</html>
This is my main file:
<?php
session_start();
require __DIR__ . '/../vendor/autoload.php';
use Knp\Snappy\Pdf;
$pdf = new Pdf('pdf\wkhtmltopdf\bin\wkhtmltopdf');
header('Content-Type: application/pdf');
// header('Content-Disposition: attachment; filename="offerte.pdf"');
$pdf->setOption('header-html', 'pdf/header.html');
$pdf->setOption('footer-html', 'pdf/footer.html');
$pdf->setOption('load-error-handling','ignore');
// I know there is a 'cover' function in WKHTMLTOPDF
$file = file_get_contents('pdf/cover.php');
echo $pdf->getOutputFromHtml($file);
?>
And as always, please: Give me an explanation and maybe an example but not just a bunch of working code!
PS: If you see any other mistakes, please let me know.