I am using Headless Chrome to render HTML into PDFs, but background color rendering in PDFs only seems to work on certain webpages.
This is the library I am using: https://github.com/chrome-php/headless-chromium-php
For the following code, if I change $url to https://www.hovec.co.uk/ then it does not render any background colors or images, and yet it works for the BBC site.
$browserFactory = new BrowserFactory("/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"); //thats my local Chrome
$browser = $browserFactory->createBrowser([
'windowSize' => [794, 1122]
]);
$url='https://www.bbc.co.uk/';
//$url='https://www.hovec.co.uk/';
// creates a new page and navigate to $url
$page = $browser->createPage();
$page->navigate($url)->waitForNavigation();
$page->pdf(['printBackground'=>true, 'marginTop' => 0.0, 'marginBottom' => 0.0, 'marginLeft' => 0.0, 'marginRight' => 0.0])->saveToFile($filepath);
$browser->close();
Any help with this would be much appreciated!