使用wkhtmltoimage渲染unicode文本

问题描述 投票:0回答:1

尝试使用wkhtmltox将HTML文件转换为图像:

./server.js

const express = require('express');
const fs = require('fs');
const wkhtmltox = require('wkhtmltox');

const app = express();
const converter = new wkhtmltox();

app.get('/tagslegend.png', (request, response) => {
  response.status(200).type('png');
  converter.image(fs.createReadStream('tagslegend.html'), { format: "png" }).pipe(response);
});

var listener = app.listen(process.env.PORT, function () {
  console.log('App listening on port ' + listener.address().port);
});

./tagslegend.html

<!doctype html>
<html>
  <body>
    <dl>
      <dt>中文</dt><dd>In mandarin language.</dd>
    </dl>
  </body>
</html>

我期待回到上面HTML的图像,例如(我的浏览器如何呈现它):

enter image description here

相反,我回来了:

enter image description here

如何使用正确的中文字符动态地将HTML呈现为png并将其提供给客户端?

javascript node.js unicode character-encoding wkhtmltoimage
1个回答
0
投票

<meta charset="utf-8">

到HTML文档的<head>

© www.soinside.com 2019 - 2024. All rights reserved.