Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome headless 如何在无头chrome实例上设置缩放级别?_Google Chrome Headless - Fatal编程技术网

Google chrome headless 如何在无头chrome实例上设置缩放级别?

Google chrome headless 如何在无头chrome实例上设置缩放级别?,google-chrome-headless,Google Chrome Headless,我想模仿用户在查看我的网页时缩小到80%。类似于 `google-chrome --headless --disable-gpu --screenshot --zoom=0.8 --window-size=1920,1080 http://www.example.com/` 但是“缩放”属性不存在,我在列表中找不到任何类似的内容: 对于人们来说,这一定是一件非常常见的事情,所以我觉得我一定错过了一些简单的事情…你不需要使用chrome无头功能,只要你有放大功能,chrome就会呈现你的css

我想模仿用户在查看我的网页时缩小到80%。类似于

`google-chrome --headless --disable-gpu --screenshot --zoom=0.8 --window-size=1920,1080 http://www.example.com/`
但是“缩放”属性不存在,我在列表中找不到任何类似的内容:


对于人们来说,这一定是一件非常常见的事情,所以我觉得我一定错过了一些简单的事情…

你不需要使用chrome无头功能,只要你有放大功能,chrome就会呈现你的css。这是我使用的css:

@media print{
    @page { margin: 2%; size: A4 }
     body { margin: 1.6cm; zoom: .7;}
     footer {
        position: fixed;
        bottom: 1;
     }
     header {
        position: fixed;
        top: 1;
     }
  }
请注意主体中的
缩放:.7
。。。要发出以下chrome headless呼叫:

chrome --headless --disable-gpu --print-to-pdf \
    'https://qto.fi:442/qto/view/installations_doc?&bid=0&as=print-doc'
奖励:如果您想要自定义带有某些徽标的页眉和页脚等,只需添加页眉和页脚标记:

 <header><p>header</p></header>
 <footer><p>footer</p></footer>
标题

页脚


添加回已删除的答案,但这正是我要寻找的答案

--force-device-scale-factor=1.5 
当您获得屏幕截图时,这将在headless实例上设置比例因子。假设您想要一个1000px×1000px网页的500px×500px图像。然后使用:

google-chrome --headless --force-device-scale-factor=0.5 --window-size=1000,1000 --screenshot=out.png https://mywebsite.com