To add a repeating footer to all pages using wkhtmltopdf and Snappy. You first have to create a separate HTML document with just the footer eg:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <div style="overflow: hidden;"> <div style="width: 50%;float: left;min-height: 1px;"> <img width="120" src="/workspace/greatannual/logo.png" alt="EGN Digital"/> </div> <div style="width: 50%;float: right; min-height: 1px;color: #333333; font-size: 20px;text-align:right;"> This is a footer</div> </div> </body> </html>
Then use the ‘footer-html’ option when building the PDF with Snappy E.g
// Load Knp require '/vendor/autoload.php'; $filename = 'created.pdf'; $filePath = '/storing-path/' . $filename; // Match server path for wkhtmltopdf binary $snappy = new Knp\Snappy\Pdf('/usr/bin/wkhtmltopdf'); // Replace this with your rendered html body $html = file_get_contents('body.html'); // Replace this with your rendered footer html $footerHtml = file_get_contents('footer'); try { $snappy->generateFromHtml( $html, $filePath, [ 'footer-html' => $footerHtml, 'page-size' => 'A4' ] ); } catch (\Exception $e) { // Set error exit; }
This results in a PDF like this:
Comments are closed.