0

我正在尝试使用 npm 将此页面呈现wkhtmltox为 png:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <style>
      html, body {
        padding: 0;
        width: 340px;
      }
      html, body, dl {
        margin: 0;
        font-size: 11px;
        font-family: Verdana, Arial;
        background-color: #fff;
      }
      dl {
        padding: 5px;
        width: 330px;
      }
      dt {
        float: left;
        clear: left;
        width: 80px;
        text-align: right;
        color: #1d439b;
      }
      dd {
        width: 240px;
        margin: 0 0 0 90px;
        padding-bottom: 0.5em;
      }
    </style>
  </head>
  <body>
    <dl>
      <dt>eargasm</dt><dd>Audio (music/effects/foley) is outstanding.</dd>
      <dt>中文</dt><dd>My favourite language (mandarin chinese).</dd>
      <dt>eyegasm</dt><dd>Mind-blowingly stunning visuals.</dd>
    </dl>
  </body>
</html>

我只是像平常一样渲染这个:

converter.image(fs.createReadStream('tagslegend.html'), { format: "png" }).pipe(response);

我得到这样的图像:

在此处输入图像描述

它的宽度为 1024 像素。

我期待一个 340 像素宽的图像。

4

1 回答 1

0

它默认为“屏幕宽度”(1024 像素)。您可以width像这样设置选项...

converter.image(fs.createReadStream('tagslegend.html'), { format: "png", width: "340" }).pipe(response);

您可以wkhtmltoimage --help在命令行运行以获得更多选项。

命令行参数映射到选项名称,但不是连字符,而是使用驼峰式大小写...例如命令行参数--foo-bar 123变为选项fooBar: '123'

于 2018-02-27T13:34:07.810 回答