使用wkhtmltoimage渲染unicode文本

时间:2018-02-23 09:07:07

标签: javascript node.js unicode character-encoding wkhtmltoimage

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

Public Sub WaitSeconds(intSeconds As Integer) On Error GoTo PROC_ERR Dim datTime As Date datTime = DateAdd("s", intSeconds, Now) Do Sleep 100 DoEvents Loop Until Now >= datTime PROC_EXIT: Exit Sub PROC_ERR: MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.WaitSeconds" Resume PROC_EXIT End Sub

./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

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

enter image description here

相反,我得到了回复:

enter image description here

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

1 个答案:

答案 0 :(得分:0)

添加

<meta charset="utf-8">

到HTML文档的<head>