从使用 Headless Chrome 创建的 PDF 中删除时间戳和页面 URL

Remove timestamp and page URL from PDF created with Headless Chrome

我有一个 PHP 应用程序,它通过将一些无头 Chrome 指令包装到命令行语句中来将网页保存为 pdf 文件,然后 运行 使用 shell_exec().

    $chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
    $location = "C:\xampp\htdocs\myfolder\files\d-{$dispatch_id}.pdf";
    $dispatch = site_url("dispatch/print_dispatch/{$dispatch_id}");
    $params = '--headless --disable-gpu --print-to-pdf="$location"';

    $command = '"'.$chrome.'"';
    $command .= "  --headless --disable-gpu --print-to-pdf=";
    $command .= '"'.$location.'"';
    $command .= ' "'.$dispatch.'"';
    $output = shell_exec($command);

    // echo $command returns:
    //"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --print-to-pdf="C:\xampp\htdocs\myfolder\files\d-71.pdf" "http://website.com/dispatch/print_dispatch/71"

这对我来说效果很好,并且完全符合我的需要。但是,生成的 pdf 文件在页眉和页脚中有日期和时间,在页脚中也有页面 url。我曾尝试使用 --no-margins 选项删除这些多余的文本,但这没有用,而且我的 Goggle-Fu 让我失望了。有没有办法从使用 Headless Chrome 创建的 pdf 中删除时间戳和 url?

我已经回顾了以下类似的问题,但还没有找到答案:

答案实际上是在另一个 Whosebug 问题中找到的:

How to remove the URL from the printing page?

<style type="text/css" media="print">
@page {
    size: auto;   /* auto is the initial value */
    margin: 0;  /* this affects the margin in the printer settings */
}
</style>

我最初尝试过这个,但是我的样式标签没有媒体属性。

附加标志 --print-to-pdf-no-header 对我有用。